Mail Archives: djgpp/1997/06/21/23:05:44
> for( i=0; i<4; printf( "%i %i\n", i, i++) );
I can't remember exactly, but I don't think you are allowed to
reference i in both places there when you modify its value.
Its one of those screwy 'undefined' outcomes in ANSI I believe.
>
> 1 0
> 2 1
> 3 2
> 4 3
>
> Is this the normal behavior?
> In C the later arguments are evaluated first? The stack?
Assuming you are using a machine that does stack based passing, then
function arguments are evaluated and passed from right to left. This
is specifically for printf style functions, where the left most argument
tells you how many others to expect. So, in this case, gcc passes the
value of I onto the stack (the rightmost one), then increments it,
then passes the left i onto the stack.
There's other gotchas like it. Try
i=10
printf("New Value = %d\n",++i + ++i);
Andrew
- Raw text -