1:#error的用法程序員
#error用於生成一個編譯錯誤消息,並中止編譯用法spa
#error messagecode
注:message不須要用雙引號包圍io
#error編譯指示字用於自定義程序員特有的編譯錯誤消息編譯
相似的,#warning用於生成編譯警告,但不會中止編譯class
#include <stdio.h> #define CONST_NAME1 "CONST_NAME1" #define CONST_NAME2 "CONST_NAME2" int main() { #ifndef COMMAND #warning Compilation will be stoped ... #error No defined Constant Symbol COMMAND #endif printf("%s\n", COMMAND); printf("%s\n", CONST_NAME1); printf("%s\n", CONST_NAME2); return 0; }
2:#line的用法file
#line用於強制指定新的行號和編譯文件名,並對源程序的代碼從新編號用法程序
#line number filenameerror
注:filename可省略top
#line編譯指示字的本質是重定義__LINE__和__FILE__
#include <stdio.h> #line 14 "Hello.c" #define CONST_NAME1 "CONST_NAME1" #define CONST_NAME2 "CONST_NAME2" void f() { return 0; } #line 14 "Hello.c" int main() { printf("%s\n", CONST_NAME1); printf("%s\n", CONST_NAME2); printf("%d\n", __LINE__); printf("%s\n", __FILE__); f(); return 0; }