Go to the first, previous, next, last section, table of contents.

The `#error' and `#warning' Directives

The directive `#error' 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 write

#ifdef __vax__
#error Won't work on Vaxen.  See comments at get_last_object.
#endif

See section Nonstandard Predefined Macros, for 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 example,

#if HASH_TABLE_SIZE % 2 == 0 || HASH_TABLE_SIZE % 3 == 0 \
    || HASH_TABLE_SIZE % 5 == 0
#error HASH_TABLE_SIZE should not be divisible by a small prime
#endif

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 be used instead.


Go to the first, previous, next, last section, table of contents.