Error Directive
The error directive is used to specify an error message for a specific situation. In the following program, the error message is displayed if USD and UKP are not defined.
Example
#include <stdio.h> #if !defined (USD) || !defined (UKP) // B #error "ERROR: NO_CURRENCY rate is specified." //C #endif int main() { printf("erro directives") // program never reaches here int rs; // error message will be flasehd from statement C getchar(); return 0; }
Explanation
- Statement B checks whether UKP or USD is defined.
- If both are not defined then the preprocessor displays an error.
Points to Remember
- The #error directive allows us to specify an error message.
- The error message is generated by the preprocessor.