4 ms·
it's a little weirder though. int main(int argc, char argv) { int a = 0; printf("%i %i %i\n", a, a++, a++); } will give "0 0 1" (gc
by jfoutz 13y ago
it's a little weirder though.
int main(int argc, char argv)
{
int a = 0;
printf("%i %i %i\n", a, a++, a++);
}
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.
- jacquesgt 13y agoThe 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.
- NAFV_P 13y agoThe 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.