Andrew Tomazos
Andrew Tomazos

Reputation: 68738

C++11 condition inclusion controlling expression "types act as if same representation as"?

In 16.1.4 (Conditional inclusion) of the C++ standard it says:

For the purposes of this token conversion and evaluation all signed and unsigned integer types act as if they have the same representation as, respectively, intmax_t or uintmax_t.

I don't understand this. What does it mean "act as if they have the same representation as"?

integer-literals are tokenized to a specific fundamental type depending on their value and suffix as explained in 2.14.2.2.

Is the 16.1.4 quote saying that their type is somehow "replaced" by intmax_t and uintmax_t? (Is this exactly equivilant to statically casting the integer literals to intmax_t or uintmax_t?)

Upvotes: 1

Views: 99

Answers (1)

James Kanze
James Kanze

Reputation: 154047

It basically means that the preprocessor doesn't have to deal with type information; it can do all of its integral arithmetic in a single type. Most of the time, it won't make a different, but it does mean that something like UINT_MAX + 1U will result in a very big number, where as outside of the preprocessor, it will result in 0.

Upvotes: 2

Related Questions