Is this undefined behavior in C / C ++?

int x = 2;
int y = 5;

int z = x +++ y;

printf("%d",z);

Both VC ++ and GCC give 7 as output. My confusion is here, it could be x ++ + y or x + ++ y. Is it defined?

+4
source share
2 answers

According to the maximum compiler, munch rules always interpret x +++ yhow x++ + y, and therefore the behavior is well defined.

C11: 6.4 Lexical elements:

p (4)

If the input stream has been parsed in the preprocessing token to the specified character, the next preprocessing token is the longest sequence of characters that can constitute the preprocessing token. [...]

p (6)

2 x+++++y x ++ ++ + y, , x ++ + ++ y .

+7

C ++ , , , ( " munch" ). , x+++y (x++) + y.

2.4/(3.3). - , , .

+7

All Articles