Stefan Näwe wrote:
as***********@gmail.com schrieb: i=0;
printf("%d %d",i++,i);
I am writing the above piece of code and executing it on different
platforms (cygwin, solaris and linux). On cywin and linux the output is
"0 0", whereas on solaris it is "0 1". What the language specification
says about this case?
5.2.2.8:
The order of evaluation of arguments is unspecified. All side effects of
argument expression evaluations take effect before the function is
entered. The order of evaluation of the postfix expression and the
argument expression list is unspecified.
However, this is not really significant here. The more important part is:
5/4:
Between the previous and next sequence point a scalar object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be accessed only to determine the value
to be stored.
The requirements of this paragraph shall be met for each allowable ordering
of the subexpressions of a full expression; otherwise the behavior is
undefined.
Since i is used with the %d format specifier above, it must be an integer,
for which operator++ doesn't give a sequence point, but it does modify i,
which is read again for the second argument. In a function call, there is
only a sequence point after _all_ arguments have been evaluated, not
between them. So the behavior is not unspecified, but undefined.