Title
Type of character literals in preprocessor expressions
Status
open
Section
15.2 [cpp.cond]
Submitter
Michael Wong

Created on 2009-06-29.00:00:00 last changed 188 months ago

Messages

Date: 2010-03-29.00:00:00

According to 15.2 [cpp.cond] paragraph 4,

The resulting tokens comprise the controlling constant expression which is evaluated according to the rules of 7.7 [expr.const] using arithmetic that has at least the ranges specified in 17.3 [support.limits], except that all signed and unsigned integer types act as if they have the same representation as, respectively, intmax_t or uintmax_t (_N3035_.18.4.2 [stdinth]). This includes interpreting character literals, which may involve converting escape sequences into execution character set members.

Ordinary character literals with a single c-char have the type char, which is neither a signed nor an unsigned integer type. Although 7.3.7 [conv.prom] paragraph 1 is clear that char values promote to int, regardless of whether the implementation treats char as having the values of signed char or unsigned char, 15.2 [cpp.cond] paragraph 4 isn't clear on whether character literals should be treated as signed or unsigned values. In C99, such literals have type int, so the question does not arise. If an implementation in which plain char has the values of unsigned char were to treat character literals as unsigned, an expression like '0'-'1' would thus have different values in C and C++, namely -1 in C and some large unsigned value in C++.

History
Date User Action Args
2009-06-29 00:00:00admincreate