Bug in argument passing?

face chrisbond@home.com
Sat Apr 22 01:04:00 GMT 2000


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