The #error Directive


# error[text]

The optional text consists of all characters immediately after the error identifier up to but not including the end of the line. Trigraph escape sequences are reduced and line continuation is respected, but comments are not discarded and macros are not recognised.


The #error directive’s sole action is to trigger a fatal error (C1189), with text inserted into the error message, e.g.,

position : fatal error C1189: #error : text 

Microsoft’s documentation is demonstrably wrong in claiming that macros are expanded in the text and indeed in suggesting that the argument to a #error directive is any sort of “token-string”. Where the relevant code identifies what to count as the text, it works directly with characters, not tokens, and is a long way even from recognising macros, let alone from deciding whether to expand them.

Apart from characters that indicate the end of a line or file, special significance is given only to the question mark (for trigraph reduction) and the backslash (for line splicing). Notably, a forward slash is just a forward slash, never the start of a comment. Anything the user may intend as a comment in a #error directive passes unchanged into the error text.