All for Joomla All for Webmasters

C #error

The #error preprocessor directive indicates error. The compiler gives fatal error if #error directive is found and skips further compilation process.

C #error example

Let’s see a simple example to use #error preprocessor directive.

  1. #include<stdio.h>
  2. #ifndef __MATH_H
  3. #error First include then compile
  4. #else
  5. void main(){
  6.     float a;
  7.     a=sqrt(7);
  8.     printf(“%f”,a);
  9. }
  10. #endif

Output:

Compile Time Error: First include then compile

But, if you include math.h, it does not gives error.

  1. #include<stdio.h>
  2. #include<math.h>
  3. #ifndef __MATH_H
  4. #error First include then compile
  5. #else
  6. void main(){
  7.     float a;
  8.     a=sqrt(7);
  9.     printf(“%f”,a);
  10. }
  11. #endif

Output:

2.645751
PinIt
submit to reddit

Leave a Reply

Top