Lập trình C - C #error
Chỉ thị tiền xử lý #error
Chỉ thị tiền xử lý #error chỉ ra lỗi. Trình biên dịch gây ra lỗi nghiêm trọng nếu chỉ thị #error được tìm thấy và bỏ qua quá trình biên dịch tiếp theo.
Ví dụ sau chúng ta dùng hàm sqrt trong thư viện math.h chưa include nó vào chương trình
#include<stdio.h>
#ifndef __MATH_H
#error First include then compile
#else
void main(){
float a;
a=sqrt(7);
printf("%f",a);
}
#endif
Kết quả:
Compile Time Error: First include then compile
#include <math.h> vào chương trình, sẽ không còn lỗi
#include<stdio.h>
#include<math.h>
#ifndef __MATH_H
#error First include then compile
#else
void main(){
float a;
a=sqrt(7);
printf("%f",a);
}
#endif
Kết quả:
2.645751