c++ - 当在 C++0x 原始字符串中取消 CPP 行拼接时,是否需要符合要求的实现来保留原始换行符序列?

标签 c++ c++11 c-preprocessor rawstring

C++0x 的最新草案 n3126 说:

Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.

...

Within the r-char-sequence of a raw string literal, any transformations performed in phases 1 and 2 (trigraphs, universal-character-names, and line splicing) are reverted.

从技术上讲,这意味着 C++ 预处理器只能识别后跟换行符的反斜杠,但我知道某些 C++ 实现也允许 Windows 或经典 Mac 风格的行结尾。

是否需要符合 C++0x 的实现来保留原始字符串的 r-char-sequence 中紧跟在反斜杠字符 \ 之后的换行符序列?也许更好的问题是:是否期望 Windows C++0x 编译器使用 "\\\r\n" 而不是 "\\\n"撤消每一行拼接?

最佳答案

翻译阶段 1 开始于

Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing newline characters for end-of-line indicators) if necessary. Trigraph sequences (2.3) are replaced [...]

我会将“在第 1 阶段和第 2 阶段执行的任何转换(三字母、通用字符名称和行拼接)”的要求解释为明确将转换从源文件字符还原为基本的源字符集。相反,源字符稍后会转换为执行字符集,并且您会在那里得到换行符。

关于c++ - 当在 C++0x 原始字符串中取消 CPP 行拼接时,是否需要符合要求的实现来保留原始换行符序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540499/

相关文章:

c++ - 在 Eclipse 中的 C++ 中链接 .lib 并在 Windows 中使用 .dll

c++ - 具有模板参数取决于参数列表

c++ - 现代 C++ : initialize constexpr tables

c++ - 可以使用 C 预处理器来判断文件是否存在吗?

c - 使用#define 为结构成员起别名

c++ - 在 C++ 类中注册 python 可调用对象

c++ - 如何知道 QDataStream 不能反序列化某些东西?

c++ - 将 CGAL 与 Code::Blocks 结合使用

c++ - 过滤参数包的类型

c - #define 语法是什么意思?