宽字符Wide Characters

ANSI 3.1.3.4 包含多个字符的整数字符常量的值或包含多个多字节字符的宽字符常量的值ANSI 3.1.3.4 The value of an integer character constant that contains more than one character or a wide character constant that contains more than one multibyte character

常规字符常量“ab”具有整数值 (int)0x6162。The regular character constant, 'ab' has the integer value (int)0x6162. 当存在多个字节时,以前读取的字节将按 CHAR_BIT 的值向左移位,并使用具有低 CHAR_BIT 位的按位“或”运算符比较下一个字节。When there is more than one byte, previously read bytes are shifted left by the value of CHAR_BIT and the next byte is compared using the bitwise-OR operator with the low CHAR_BIT bits. 多字节字符常量中的字节数不能超过 sizeof(int)(对于 32 位目标代码,为 4)。The number of bytes in the multibyte character constant cannot exceed sizeof(int), which is 4 for 32-bit target code.

如上所述读取多字节字符常量,并使用 mbtowc 运行时函数将其转换为宽字符常量。The multibyte character constant is read as above and this is converted to a wide-character constant using the mbtowc run-time function. 如果结果不是有效的宽字符常量,则将发出错误。If the result is not a valid wide-character constant, an error is issued. 在任何情况下,mbtowc 函数检查的字节数限制为 MB_CUR_MAX 的值。In any event, the number of bytes examined by the mbtowc function is limited to the value of MB_CUR_MAX.

另请参阅See Also

字符Characters