Clang mentioned this thingy to me when I was trying some various non-std ways to find std::numeric_limits<size_t>::max()
for my allocator::max_size()
The expression size seems limited at 4 bytes so it looks pretty much like an impl-defined multi-byte char but I don't know how it works exactly.
printf("0x%016hhX\n", '\377'); // 0x00000000000000FF
printf("0x%016X \n", '\3777'); // 0x000000000000FF37
printf("0x%016X \n", '\37777'); // 0x0000000000FF3737
printf("0x%016X \n", '\377777'); // 0x00000000FF373737 [-Wfour-char-constants]
printf("0x%016X \n", '\3777777'); // 0x0000000037373737 [ too long ]
printf("0x%016X \n", '\3777777'); // 0x0000000037373737 [ too long ]
Line 2 - 4 all seem return int but only 4th line warn of -Wfour-char-constants
if turn on -Weveryting
. Why does 4-byte char have to warn its user?
Please explain how it works. Does it have any colloquial or probably normative term?
The behaviour on using more than 3 digits with an octal constant specified by
\
and enclosed in single quotation characters is not defined by the C++ standard. (Interestingly, you can define multicharacter constants using more than 2 hexadecimal digits, or even notation like'ab'
but the value of theint
you get is implementation defined.)Consult your compiler documentation for the treatment of a longer octal constant.