There's a clause I was never sure I understood the point of but I think it exists to forbid the following initialization:
int main(void) {
int x = ( (x = 1), 2);
}
There's a clause I was never sure I understood the point of but I think it exists to forbid the following initialization:
int main(void) {
int x = ( (x = 1), 2);
}
@gsuberland It is, as you say, a comma operator, the thing that builds an expression e1, e2 from two expressions e1 and e2 with a precedence I am unsure of.
The comma that appears when initializing a compound type, or when applying a function of several arguments, is NOT a comma operator. If it were C++ and you overloaded the comma operator, these things would still behave as they did.
e1, e2 evaluates e1, discards the result, sequence point, evaluates e2 and yields whatever that yields.
@void_friend thanks.
and... sigh. I hate these weird syntax shenanigans.
x containing either 1 or 2. But it's not really conclusive, because https://cigix.me/c17#6.7.9.p23 is only about the initialization list expressions with respect to each other, not with respect to the initializations. Also I would like to point out that there are people that argue that (starting with x==0, the expression (0, (x*=2), 0) + (0, x++, 0) has UB (rather than leaving x in an unspecified state of either 1 or 2). I never understood these people's argument but by the same token, the first example in this thread would be UB.