宏指令#error的用法
编译过程中,一旦遇到这条宏指令,便会终止编译,读该宏指令,显示出错误信息后而停止。 用法如下: #line 错误信息 实例: #if !defined(__cplusplus) #error C++ compiler required. #endif When #error directives are encountered, compilation terminates.
宏指令#line的用法
宏指令#line可用来修改C中所定义的__LINE__和__FILE__等宏定义的内容。 用法如下: #line 行号 '文件名' 注意该行号为原文件中当前行号,文件名为当前编译的文件名。 实例: #include <stdio.h>; int main(void) { #line 9999 printf(helo); return 0; } 因为没有helo的定义,所以编译会报错,此时加入的宏指令#line才会看到效果。 编译器会提示 "a.c", line 9999: error: undefined symbol: helo "a.c", line 9999: warning: improper pointer/integer combination: arg #1 就是把当前行当作9999行了。 这样可以有利于错误代码的定位。