I'm trying to pin down my understanding of sequence points in C -- just wanted to check something. At present, I believe that (1) is undefined whereas (2) is merely unspecified, on the basis that in (2), there are sequence points after evaluating the arguments for g
and h
(so we're not modifying i
twice between sequence points), but the order of evaluation of the arguments of f
is still unspecified. Is my understanding correct?
#include <stdio.h>
int g(int i) {
return i;
}
int h(int i) {
return i;
}
void f(int x, int y) {
printf("%i", x + y);
}
int main() {
int i = 23;
f(++i, ++i); // (1)
f(g(++i), h(++i)); // (2)
return 0;
}
EDIT:
It seems the key point here is whether the compiler is free to perform both the increments before either g
or h
is called -- my understanding from the answers below is that it is, although I'd appreciate confirmation that that's the case.