Trivia impact: rare
The Character With Size One
a quoted character that is not an int in C++
Does C++ give a character literal the same type as C does?
Why¶
In C++, [lex.ccon] gives an ordinary character literal such as 'C' the type char.
That differs from C, where the corresponding literal has type int. [expr.sizeof]
defines sizeof(char) as one, regardless of how many bits a byte has on the machine,
so the observed result is guaranteed rather than a GCC detail.
Where it shows up¶
It mostly surprises people translating C macros or using a character literal in a
compile-time overload or type-trait test. Normal character arithmetic still promotes
the char to an integer, which can hide the distinction in everyday expressions.
Takeaway: In C++, 'x' is a char; in C, it is an int.
Try it: g++ -std=c++17 main.cpp -o demo && ./demo