Re: evaluation order of expressions in gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi laura,

It's best not to depend on the order, at all.

x = f() + g();
y = f() + g();

It is possible, and allowed, that the first one will do f then g, and the second one will do g then f. The compiler may have enough information to realize it has a cached result of g.

Even with NO optimizations, you cannot make any assumptions on which will happen first.

If you REALLY need to have a particular order, use explicit temporaries:

fv = f();
gv = g();
x = fv + gv;
fv = f();
gv = g();
y = fv + gv();

But, in my opinion, if the f() and g() functions have a order interdependency, the design is flawed.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux