Look at this code snippet:
int a = 0xe+1;
Clang, gcc, icc don't compile this:
t.cpp:1:12: error: invalid suffix '+' on integer constant
MSVC successfully compiles.
Which compiler is correct? If clang and gcc are correct, why is this happening?
Note: if I add a space before +
, the code compiles. If I change 0xe
to 0xf
, it compiles too. Maybe this has to do something with exponential notation (like 1.2e+3
)?
0xe+1
is treated as a single "preprocessing number" preprocessing token. This tokenization rule doesn't quite line up with the definition of numeric literals in the ordinary grammar; preprocessing numbers are defined as
pp-number:
digit
. digit
pp-number digit
pp-number identifier-nondigit
pp-number ' digit
pp-number ' nondigit
pp-number e sign
pp-number E sign
pp-number p sign
pp-number P sign
pp-number .
If the tokenization rules were based on the numeric literal definitions instead of the simpler "preprocessing number" definition, your expression would be tokenized as 0xe + 1
, but since the rules don't match up, you get a single 0xe+1
token, which is not a valid literal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With