Implementation of string literal concatenation in C and C++

后端 未结 5 1914
北海茫月
北海茫月 2021-01-12 03:05

AFAIK, this question applies equally to C and C++

Step 6 of the \"translation phases\" specified in the C standard (5.1.1.

5条回答
  •  执笔经年
    2021-01-12 03:25

    In the ANSI C standard, this detail is covered in section 5.1.1.2, item (6):

    5.1.1.2 Translation phases
    ...

    4. Preprocessing directives are executed and macro invocations are expanded. ...

    5. Each source character set member and escape sequence in character constants and string literals is converted to a member of the execution character set.

    6. Adjacent character string literal tokens are concatenated and adjacent wide string literal tokens are concatenated.

    The standard does not define that the implementation must use a pre-processor and compiler, per se.

    Step 4 is clearly a preprocessor responsibility.

    Step 5 requires that the "execution character set" be known. This information is also required by the compiler. It is easier to port the compiler to a new platform if the preprocessor does not contain platform dependendencies, so the tendency is to implement step 5, and thus step 6, in the compiler.

提交回复
热议问题