Re:A glimpse of undefined behavior in C
by jacquesgt on Saturday November 30, 2013 @05:45PM
(#6825018)
The issue here is that the order of function argument evaluation is undefined. If the commas weren't inside of a function call, they would result in sequence points. So, this would be well defined:
int a = 0, b, c;
b = a++, c = a++;
But, there is no defined order in which to evaluate function arguments.The example given in the article shows all the code, but your example involves a function so the code in question is hidden. The behaviour partially depends on how the function is written.
"0 0 1" is what I would expect from your code, and identifier a should end up as 2.
will give "0 0 1" (gcc 4.2.1), the increment "shouldn't" happen until after the ; if you're going with post statement. I think your rule would expect "0 0 0" with a being 2 after the printf.
BUT! you get a warning, so that's nice.