AFAIK, this question applies equally to C and C ++
Step 6 of the "translation phases" specified in the C standard (5.1.1.2 in the draft C99 standard) indicates that adjacent string literals should be combined into one literal. Ie
printf("helloworld.c" ": %d: Hello " "world\n", 10);
It is equivalent (syntactically):
printf("helloworld.c: %d: Hello world\n", 10);
However, the standard does not indicate which part of the compiler should handle this - whether it should be a preprocessor ( cpp ) or the compiler itself. Some online research tells me that this function should usually be performed by a preprocessor ( source # 1 , source # 2 , and there are more), which makes sense.
However, running cpp on Linux shows that cpp does not:
eliben@eliben-desktop:~/test$ cat cpptest.c int a = 5; "string 1" "string 2" "string 3" eliben@eliben-desktop:~/test$ cpp cpptest.c # 1 "cpptest.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "cpptest.c" int a = 5; "string 1" "string 2" "string 3"
So my question is: where should this language function be processed, in the preprocessor or in the compiler itself?
There may not be a single good answer. Heuristic answers based on experience, well-known compilers and overall good engineering practice will be evaluated.
PS If you're wondering why I care about this ... I'm trying to find out if my Python-based P analyzer should handle string literal concatenation (which is not currently running), or leave it with the cpp that it accepts before running.
c ++ c c-preprocessor string-literals
Eli bendersky
source share