Bug in argument passing?
Neil Booth
NeilB@earthling.net
Sat Apr 22 06:11:00 GMT 2000
Thanks for your bug report.
Arguments to a function can be evaluated in any order the compiler
chooses (it's not specified). Hence evaluating ++booya before booya=0
is valid, and this is not a GCC bug, but an ambiguity in your code.
Neil.
face wrote:-
> Hello.
>
> I think I've discovered a bug in how egcs passes arguments to functions. More specifically, the bug is exposed when a parameter is changed as it is passed.
>
> As an example:
>
> void foo(int a, int b)
> {
> printf("%d, %d\n", a, b);
> }
>
> ...
>
> int booya;
>
> foo((booya = 0), ++booya);
>
> (End example.)
>
> Logically, this should print the string "0, 1". Possibly because the arguments are pushed onto the stack in reverse order, this is not the case. What is does print is:
>
> 0, <uninitialized integer>
>
> If you look at how it's compiled down (keeping in mind that the arguments are pushed onto the stack in reverse order), it makes perfect sense:
>
> 'booya'--uninitialized--is incremented and then pushed on to the stack, then:
> 'booya' is initialized to zero, then pushed onto the stack.
>
> I'm using egcs version 2.95.2 on FreeBSD 5.0-CURRENT (i386). I passed no unusual flags to the compiler (just 'gcc -o foo foo.c').
>
>
> Regards,
>
>
> Christopher L. Bond
>
More information about the Gcc-bugs
mailing list