Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C #error directive and comments

Given:

#error /*
*/ foo

Microsoft C++ outputs an error message of /* and GCC outputs foo.

Which is correct?

like image 951
rwallace Avatar asked Jun 10 '13 09:06

rwallace


2 Answers

GCC is correct.

Replacement of comments (including line-breaks) happens in translation phase 3, pre-processing in translation phase 4 (ISO/IEC 9899:1999, §5.1.1.2).

Hence, the preprocessing part of the compiler does not "see" the line-breaks anymore.

And, #error is defined like this (§6.10.5):

A preprocessing directive of the form

# error pp-tokens_opt new-line

causes the implementation to produce a diagnostic message that includes the specified sequence of preprocessing tokens.

So, the foo has to be part of the output.

like image 159
undur_gongor Avatar answered Nov 03 '22 02:11

undur_gongor


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

like image 26
BLUEPIXY Avatar answered Nov 03 '22 00:11

BLUEPIXY