Is this considered undefined behaviour in C/C++?

c, c++, undefined-behavior

Solution

According to maximal munch rule compiler always interpret `x +++ y` as `x++ + y` and therefore behaviour is well defined.

C11: 6.4 Lexical elements:

p(4)

If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token.[...]

p(6)

EXAMPLE 2 The program fragment `x+++++y` is parsed as `x ++ ++ + y`, which violates a constraint on increment operators, even though the parse `x ++ + ++ y` might yield a correct expression.

Problem

``` int x = 2; int y = 5; int z = x +++ y; printf("%d",z); ``` Both VC++ and GCC give 7 as output. My confusion here is, it could be x++ + y, or x + ++y. Is this defined?

Original source

Related problems