A
aleksa
Suppose I'm given a ptr to RECT and am modifying the RECT in a loop:
V1:
void ModifyRect (RECT* prect);
{
while (cond) {
if (newleft < prect->left) prect->left = newleft;
.
.
.
}
}
V2:
void ModifyRect (RECT* prect);
{
RECT rect;
while (cond) {
if (newleft < rect.left) rect.left = newleft;
.
.
.
}
*prect = rect;
}
(newleft is read sequentially from somewhere)
Compiler generated code for V1 accesses memory all the time,
while V2 holds everything in registers and only updates
the prect when finished.
I don't see a reason why both versions aren't coded the same.
(there is no VOLATILE anywhere...)
Just wondering, is this compiler specific or a C rule?
V1:
void ModifyRect (RECT* prect);
{
while (cond) {
if (newleft < prect->left) prect->left = newleft;
.
.
.
}
}
V2:
void ModifyRect (RECT* prect);
{
RECT rect;
while (cond) {
if (newleft < rect.left) rect.left = newleft;
.
.
.
}
*prect = rect;
}
(newleft is read sequentially from somewhere)
Compiler generated code for V1 accesses memory all the time,
while V2 holds everything in registers and only updates
the prect when finished.
I don't see a reason why both versions aren't coded the same.
(there is no VOLATILE anywhere...)
Just wondering, is this compiler specific or a C rule?