Re: Function Argument Evaluation

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

 



Hi Brian,

There is no guarantee whatsoever as to the order of evaluation of arguments
passed into functions.

int i = 0;
Foo(++i, ++i, ++i); // Foo(1,2,3)? Foo(3,2,1)? Foo(3,3,3)? Other...?

You can't even rely on seemingly identical steps having same order of
evaluation.

int i = 0;
int j = 0;
Foo(++i, ++i, ++i); // e.g., Foo(1,2,3);
Foo(++j, ++j, ++j); // e.g., Foo(2,3,1); Surprise!

If your code relies on particular order-of-evaluation, break out those
evaluations into separate lines of code and use explicit variables to hold
the result which are passed into the function.

I was bit by this back in the 80's when I got my first optimizing compiler.

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