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

发布于 2024-10-09 11:53:35 字数 458 浏览 3 评论 0原文

C++0x 的最新草案 n3126 表示:

删除紧跟换行符的反斜杠字符 (\) 的每个实例,拼接物理源代码行以形成逻辑源代码行。

...

在原始字符串文字的r-char-sequence内,执行的任何转换 第 1 阶段和第 2 阶段(三字母组、通用字符名称和行拼接)已恢复。

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

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

The latest draft of C++0x, n3126, says:

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.

Technically this means that the C++ preprocessor only recognizes a backslash followed by the newline character, but I know that some C++ implementations also allow Windows- or classic Mac-style line endings as well.

Will conforming implementations of C++0x be required to preserve the newline sequence that immediately followed a backslash character \ within the r-char-sequence of a raw string? Maybe a better question is: would it be expected of a Windows C++0x compiler to undo each line splice with "\\\r\n" instead of "\\\n"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜声 2024-10-16 11:53:35

翻译阶段 1 开始于

物理源文件字符是
映射,在实现定义的
方式,到基本源字符
设置(引入换行符
对于行尾指示器)如果
必要的。三字图
序列 (2.3) 被替换 [...]

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

Translation phase 1 starts with

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 [...]

I'd interpret the requirement "any transformations performed in phases 1 and 2 (trigraphs, universal-character-names, and line splicing)" as explicitly not reverting the transformation from source file characters to the basic source character set. Instead, source characters are later converted to the execution character set, and you get newline characters there.

盗琴音 2024-10-16 11:53:35

如果需要特定的行结束序列,可以显式插入它,并使用字符串文字连接:

char* nitpicky = "I must have a \\r\\n line ending!\r\n"
"Otherwise, some other piece of code will misinterpret this line!";

If you need a specific line ending sequence, you can insert it explicitly, and use string literal concatenation:

char* nitpicky = "I must have a \\r\\n line ending!\r\n"
"Otherwise, some other piece of code will misinterpret this line!";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文