Contents|Index|Previous|Next

The #error and #warning Directives

The #error directive causes the preprocessor to report a fatal error. The rest of the line that follows #error is used as the error message.

You would use #error inside of a conditional that detects a combination of parameters which you know the program does not properly support. For example, if you know that the program will not run properly on a Vax, you might use the following input.

See Nonstandard Predefined Macros for a description of why this works.

If you have several configuration parameters that must be set up by the installation in a consistent way, you can use conditionals to detect an inconsistency and report it with #error. For clarification, see the following example.

The directive #warning is like the directive #error, but causes the preprocessor to issue a warning and continue preprocessing. The rest of the line that follows #warning is used as the warning message.

You might use #warning in obsolete header files, with a message directing the user to the header file which should instead be used.