C ++预处理程序字符串文字串联 [英] C++ Preprocessor string literal concatenation
问题描述
我发现了此关于 C 预处理器应如何处理字符串文字串联(阶段6)的信息。但是,我找不到有关在C ++中如何处理的任何信息(C ++是否使用 C 预处理程序?)。
I found this regarding how the C preprocessor should handle string literal concatenation (phase 6). However, I can not find anything regarding how this is handled in C++ (does C++ use the C preprocessor?).
我询问的原因是我有以下内容:
The reason I ask is that I have the following:
const char * Foo::encoding = "\0" "1234567890\0abcdefg";
其中 encoding
是类的静态成员 Foo
。没有连接,我将无法像这样写出这样的字符序列。
where encoding
is a static member of class Foo
. Without the availability of concatenation I wouldnt be able to write that sequence of characters like that.
const char * Foo::encoding = "\01234567890\0abcdefg";
由于 \012
被解释。
我没有访问多个平台的权限,我很好奇我对上述操作始终正确的信心,即我将永远get {0,'1','2','3',...}
I dont have access to multiple platforms and I'm curious how confident I should be that the above is always handled correctly - i.e. I will always get { 0, '1', '2', '3', ... }
推荐答案
语言(C和C ++)没有预处理器。作为单独的功能单元,预处理器是实现细节。如果由所谓的翻译阶段定义,则处理源文件的方式。 C和C ++中的一个阶段涉及串联字符串文字。
The language (C as well as C++) has no "preprocessor". "Preprocessor", as a separate functional unit, is an implementation detail. The way the source file(s) is handled if defined by so called phases of translation. One of the phases in C, as well as in C++ involves concatenating string literals.
在C ++语言标准中,它在2.1中进行了描述。对于C ++(C ++ 03),它是阶段6
In C++ language standard it is described in 2.1. For C++ (C++03) it is phase 6
6并置了相邻的普通字符串文字
标记。相邻的宽
字符串文字标记是
串联的。
6 Adjacent ordinary string literal tokens are concatenated. Adjacent wide string literal tokens are concatenated.
这篇关于C ++预处理程序字符串文字串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!