@
codehz #30
但这种写法按标准[^1]会得到一个「实现定义」的值。
> The value of an integer character constant containing more than
> one character (e.g., 'ab'), or containing a character or escape
> sequence that does not map to a single-byte execution character,
> is implementation-defined.
考虑到可移植性,通常不建议使用。
除非你写的代码只应用于特定实现,且该实现对此有明确定义。
比如在 GCC[^2] 中:
> The compiler evaluates a multi-character character constant
> a character at a time, shifting the previous value left by the
> number of bits per target character, and then or-ing in the
> bit-pattern of the new character truncated to the width of a
> target character.
[^1]: ISO/IEC 9899:1999 §6.4.4.4/10
[^2]:
https://gcc.gnu.org/onlinedocs/cpp/Implementation-defined-behavior.html---
声明:本回答并非使用 LLM 生成。