Anders, Verdi, On Saturday 10 September 2005 00:39, Anders Johansson wrote:
On Saturday 10 September 2005 08:35, Verdi March wrote:
Hi,
Just want to confirm that the following statements is 'dangerous', in the sense that it's system dependant. I recall to read somewhere there're additional case where this can happen, such as dofun(s, s++).
Any insight on why it happens is highly appreciated.
Here's the program: int main(void) { int s=3; printf("s=%i,s=%i,s=%i\n",s,s++,s--); return 0; }
For the result, I got s=3,s=2,s=3 on SuSE 9.3, but on a Solaris machine, I got s=3,s=3,s=4.
...
Your example is equivalent to this, because you are modifying s twice between two sequence points. Not allowed. You probably wanted something like
printf("s=%i,s=%i,s=%i\n",s,s+1,s-1);
Perhaps. Verdi used _post_ -increment and -decrement, so apart from the ambiguity introduced by the compiler's freedom to order the evaluation of the function arguments any way it wishes, his code tried to say he wanted the value of 's' _before_ incrementing or decrementing 's', not after. One might suspect he wanted this: printf("s=%i,s=%i,s=%i\n", s, s, s + 1);
...
Randall Schulz