#error和#line实例
1.#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.#include <stdio.h>
#line 14 "Hello.c"
#define CONST_NAME1 "CONST_NAME1"
#define CONST_NAME2 "CONST_NAME2"
void f()
{
return 0;
}
int main()
{
printf("%s\n", CONST_NAME1);
printf("%s\n", CONST_NAME2);
printf("%d\n", __LINE__);
printf("%s\n", __FILE__);
f();
return 0;
}
//#line用于强制指定新的行号和编译文件名, 并对源程序的代码重新编号
//#warning用于生成编译警告, 但不会停止编译
//#error用于生成一个编译错误消息, 并停止编译
/******************************** Stay hungry, Stay foolish. @Rocky ********************************/