The #error directive

A preprocessor error directive causes the preprocessor to generate an error message and causes the compilation to fail.

Read syntax diagramSkip visual syntax diagram#error directive syntax
 
             .--------------------.
             V                    |
>>-#--error----preprocessor_token-+----------------------------><
 

The #error directive is often used in the #else portion of a #if-#elif-#else construct, as a safety check during compilation. For example, #error directives in the source file can prevent code generation if a section of the program is reached that should be bypassed.

For example, the directive

#define BUFFER_SIZE 255

#if BUFFER_SIZE < 256
#error "BUFFER_SIZE is too small."
#endif

generates the error message:

BUFFER_SIZE is too small.