第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
}
小结:
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论