C # error directive and comments

Given:

#error /* */ foo 

Microsoft C ++ displays the /* error message and the GCC foo outputs.

What is right?

+7
source share
2 answers

GCC is correct.

Comments are replaced (including line breaks) in phase 3 of the translation, preprocessing in phase 4 of the translation (ISO / IEC 9899: 1999, Β§5.1.1.2).

Therefore, the compiler preprocessing part no longer β€œsees” line breaks.

And, #error is defined as follows (Β§6.10.5):

Form preprocessing directive

# error pp-tokens_opt new-line

leads to the fact that the implementation creates a diagnostic message that contains the specified sequence of pre-processing tokens.

So foo should be part of the output.

+7
source

GCC is correct because it must be replaced with a single space / * ... * / in the standard.

+2
source

All Articles