Function Argument Evaluation
Daniel Llorens del Río
daniel.llorensdelrio@epfl.ch
Wed Dec 6 16:00:00 GMT 2006
On 6 Dec, 2006, at 16:48, Brian D. McGrew wrote:
> Good morning,
>
> Historically it's always been that arguments passed into functions get
> evaluated from left to right
Not true.
> Ie. 'int foo(int a, char *b, float c) { }
>
> But I'm noticing that with gcc-4.1.1 (on Fedora Core 5), that does not
> seem to be the case. We have some code, granted it may be fragile or
> broken code, that relies on the arguments being evaluated from left to
> right and seems like that's not the case. In my code the arguments
> seem
> to be being evaluated right to left.
I /think/ that with -O0 the arguments are evaluated left to right.
However, neither the standards nor gcc make any guarantee about
argument evaluation order. Not now and not historically either. Any
code that relies on a particular order of evaluation is broken.
You've just been lucky (or not, depending on the point of view) up to
now. It is typical that such bugs are exposed when the optimization
level is changed, which is a good reason to test regularly with both -
O0 and -O2.
More information about the Gcc-help
mailing list