当 C++0x 原始字符串中取消 CPP 行拼接时,是否需要一致的实现来保留原始换行序列?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
翻译阶段 1 开始于
我将要求“在第1阶段和第2阶段执行的任何转换(三字母、通用字符名称和行拼接)”解释为明确不将源文件字符的转换恢复为基本源字符集。相反,源字符稍后会转换为执行字符集,并且您会在那里得到换行符。
Translation phase 1 starts with
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.
如果需要特定的行结束序列,可以显式插入它,并使用字符串文字连接:
If you need a specific line ending sequence, you can insert it explicitly, and use string literal concatenation: