C ++ preprocessor string literal concatenation

I found this regarding how the C preprocessor should handle string literal concatenation (step 6). However, I can not find anything about how this is handled in C ++ (if using C ++ preprocessor is the C ?).

I ask that I have the following:

const char * Foo::encoding = "\0" "1234567890\0abcdefg";

where encodingis the static member of the class Foo. Without concatenation accessibility, I would not be able to write a sequence of characters like this.

const char * Foo::encoding = "\01234567890\0abcdefg";

Something completely different due to interpretation \012.

I don't have access to multiple platforms, and I'm curious how confident I am that the above is always handled correctly - i.e. i always get{ 0, '1', '2', '3', ... }

+6
source share
3 answers

The language (C, as well as C ++) does not have a "preprocessor". A “preprocessor”, as a separate functional unit, is an implementation detail. The method of processing the source file (s), if it is determined by the so-called translation phases. One of the phases in C, as well as in C ++, involves concatenation of string literals.

In the C ++ language standard, it is described in 2.1. For C ++ (C ++ 03) this is phase 6

6 Adjacent regular string literal tokens combined. Adjacent wide string literals are concatenated.

+10
source

Yes, it will be processed as you describe, because in step 5,

escape- set (C99 §5.1.1.2/1)

++ 03 :

, escape- - (++ 03 §2.1/5)

, escape- (, \0) 5, .

+6

- ++ C. , , ++ C, , ++ C.

0

All Articles