blogger Indonesia

Follow judhyns blog

ERROR DIRECTIVE

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

  1. Statement B checks whether UKP or USD is defined.

  2. If both are not defined then the preprocessor displays an error.

Points to Remember

  1. The #error directive allows us to specify an error message.

  2. The error message is generated by the preprocessor.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |