第23课 #error和#line使用分析(一些编译器已经没有这两个预编译标识符了,了解即可)

error的用法

·#error用于生成一个编译错误消息
·用法
#error message
message不需要用双引号包围
#error编译指示字用于自定义程序员特有的编译错误消息
类似的,#warning用于生成编译警告。
#error是一种预编译器指示字
#error可用于提示编译条件是否满足

例子23-2:
#include "stdio.h"

define product 6

void f()
{

#if(product == 1)
printf("low!\n");
#elif(product == 2)
printf("middle!\n");
#elif(product == 3) 
printf("high!\n");
#else
#error the productis not defined!
#warning the productis not defined!
#endif

}
int main()
{

f();
#if(product == 1)
printf("111!\n");
#elif(product == 2)
printf("222!\n");
#elif(product == 3)
printf("3333!\n");
#endif

}
小结:

error用于自定义一条编译错误信息

warning用于自定义一条编译警告信息

error和#warning场应用于条件编译

line 用于强制指定新的行号和编译文件名

你可能感兴趣的:(c++,c)