Possible Duplicate:
C++ source in unicode
刚刚在项目中发现了这行代码:
string überwachung;
我很惊讶,因为实际上我认为你不允许在 C++ 代码中使用变音符号,而不是在字符串等中,这会导致编译器错误。但这在 visual studio 2008 中编译得很好。
- 这是微软的一项特殊功能,还是其他编译器也允许使用变音符号?
- 是否存在任何潜在问题(可移植性、系统语言设置……)?
- 我清楚地记得这是不允许的。什么时候变的?
亲切的问候任何澄清
P.S.:工具 cppcheck 甚至会将此用法标记为错误,即使它可以编译
GCC 对此提示:
codepad
: error: stray '\303' in program
C++ 语言标准本身将 基本源字符集 限制为 91 个可打印字符加上制表符、换页符和换行符,这些都在 ASCII 中。但是,有一个很好的脚注:
The glyphs for the members of the basic source character set are intended to identify characters from the subset of
ISO/IEC 10646 which corresponds to the ASCII character set. However, because the mapping from source file characters to the
source character set (described in translation phase 1) is specified as implementation-defined, an implementation is required to
document how the basic source characters are represented in source files.
.. 翻译阶段 1 是(强调我的)
Physical source file characters are mapped, in an implementation-defined manner, to the basic source
character set (introducing new-line characters for end-of-line indicators) if necessary. The set of physical
source file characters accepted is implementation-defined.
通常,您不应在代码中使用变音符号或其他特殊字符。如果可能有效,但如果有效,则它是特定于编译器的功能。