This is, I believe, a pedantic question. However since the FAQ does not seem to disallow pedantry I’ll go ahead and ask since I am genuinely interested in the answer.
I’m trying to read and understand (most of) the C99 standard (ISO/IEC 9899:1999). I’m basically wondering whether this is strictly conforming code:
printf("String literal 1 "
"String literal 2.\n");
Or should the newline be escaped like this:
printf("String literal 1 "\
"String literal 2.\n");
The relevant section of the standard seems to be section 5.1.1.2, which describes the translation phases. In phase 2 each “\” followed by a newline is deleted, splicing the lines into one line. Then in phase 6, adjacent string literal tokens are concatenated.
So for the first code sample to be conforming I see two options: Either string literals separated by a newline are considered adjacent, or the newline characters are removed in one of the previous translation phases.
So does anyone know if the first code sample above can be considered strictly conforming in this context, and if so is there something in the standard that makes this absolutely clear?
I believe they are both strictly conforming. The \ is a different feature than string literal concatenation. So your first example is definitely fine: there is a new line character between the literals, which is a white space, and thus forms a “sequence of
white-space characters” as mentioned in 5.1.1.3.
The C standard in 5.1.1.2 is a bit unclear regarding the \ though, as it vaguely suggests that the new line character is removed as well as the backslash. But in this particular case it shouldn’t matter whether there are white space characters between the string literals or not, I believe that your first example will be interpreted as
“String literal 1 “”String literal 2.\n”
which in turn results in the expected output.