c++ - 在 C++ 代码中使用 "umlauts"

标签 c++ compiler-construction

<分区>

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.

通常,您不应在代码中使用变音符号或其他特殊字符。如果可能有效,但如果有效,则它是特定于编译器的功能。

关于c++ - 在 C++ 代码中使用 "umlauts",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636729/

相关文章:

c++ - CRTP 和多级继承

c++ - VC++ : Weird compiler errors

c - 用于教育目的的小型 c 编译器

C++ - str(n)cmp(i) () 用于 C++ 样式字符串

c++ - 体系结构 x86_64 链接 constexpr std::array 的 undefined symbol

python - Pybind11 : "ImportError: DLL not found" when trying to import *. Python解释器中的pyd

c - 在 Linux 上模拟电路和编程微 Controller

compiler-construction - 在 llvm 中定义使用链

compiler-construction - 学习编写编译器

c++ - 制作 :*** [Lab1] Error 1