Introduction
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.
Program
Suppose we have three files:
file1.h #define USD 1 file2.h #define UKP 1 file3 #include#include //A #if !defined (USD) || !defined (UKP) // B #error "ERROR: NO_CURRENCY rate is specified." //C #endif main() { int rs; rs = 10 * currency_rate; //D printf ("%d\n", rs); }
Explanation
Points to Remember
-
The #error directive allows us to specify an error message.
-
The error message is generated by the preprocessor.
No comments:
Post a Comment