zwei stringliterale aneinanderhängen
-
also ich weiß dass das hier geht:
const char* foo = "hall" "o w" "elt";aber wieso? genauer gesagt, wo im standard steht, dass das geht?
-
Phase Sechs der Übersetzung:
[lex.phases]/6 schrieb:
6. Adjacent string literal tokens are concatenated.
-
Es steht sowohl im Abschnitt über Stringliterale sowie im Abschnitt über die Phasen der Übersetzung. Wo hast du gesucht?
-
Genauer wird das Ganze in [lex.string]/13 beschrieben:
In translation phase 6 (2.2), adjacent string literals are concatenated. If both string literals have the same encoding-prefix, the resulting concatenated string literal has that encoding-prefix. If one string literal has no encoding-prefix, it is treated as a string literal of the same encoding-prefix as the other operand. If a UTF-8 string literal token is adjacent to a wide string literal token, the program is ill-formed. Any other concatenations are conditionally supported with implementation-defined behavior.
[ Note: This concatenation is an interpretation, not a conversion. Because the interpretation happens in translation phase 6 (after each character from a literal has been translated into a value from the appropriate character set), a string literal’s initial rawness has no effect on the interpretation or well-formedness of the concatenation. — end note ]
[...]
Characters in concatenated strings are kept distinct.
[ Example:"\xA" "B"contains the two characters
’\xA’and’B’after concatenation (and not the single hexadecimal character’\xAB’). — end example ]