M
Markus Wichmann
The question is posted in this group many times.
Read the FAQ. The result is undefined - that is,
it is DEFINED to be undefined. That means it is
okay for the result to be different in different
compilers, and it is even okay for it to be
different in the same compiler in different
places or at different times.
On a related note, what about the following:
static int foo;
static int bar(void)
{
return foo++;
}
int main(void)
{
return foo++ - bar();
}
The standard sticks a sequence point between the evaluation of a
function call's arguments but not after its return. bar() is not
guarenteed to be called before or after evaluation of foo++, so bar()
can have different results. So does the above program exhibit UB?
Because if it does, that means that no-one should use function calls in
compound expressions. Unless the function called is pure or there's only
one function call which is compounded only with local variables (i.e.
variables with a scope smaller than file scope).
Ciao,
Markus