Previous Page
Next Page

14.5. Generating Error Messages

The #error directive makes the preprocessor issue an error message, regardless of any actual formal error. Its syntax is:

    #error [text]

If the optional text is present, it is included in the preprocessor's error message. The compiler then stops processing the source file and exits as it would on encountering a fatal error. The text can be any sequence of preprocessor tokens. Any macros contained in it are not expanded. It is a good idea to use a string literal here to avoid problems with punctuation characters, such as single quotation marks.

The following example tests whether the standard macro _ _STDC_ _ is defined, and generates an error message if it is not:

    #ifndef _  _STDC_  _
      #error  "This compiler does not conform to the ANSI C standard."
    #endif


Previous Page
Next Page