C是否允许8字节长的多字符文字?
作者:互联网
为什么允许这样做:
uint32_t x = 'name';
但这会被截断为32位:
uint64_t x = 'namename';
有没有办法有一个8字节长的多字符文字?
解决方法:
是的,只要您的编译器具有8字节的整数并支持它.
关于多字符文字,C标准非常简洁.这就是它就此事所说的全部(C 14,2.14.3 / 1):
An
ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter
literal, or an ordinary character literal containing a single c-char not representable in the execution character
set, is conditionally-supported, has typeint
, and has an implementation-defined value.
(强调我的)
如您所见,几乎所有标准都表示如果支持多字符文字(它们不一定是),则它们的类型为int.该值取决于编译器.
标签:c,character,literals 来源: https://codeday.me/bug/20190727/1557407.html