预编译指示符
error.c
#include <stdio.h>
#if(VERSION < 3)
#error "版本过低"
#elif (VERSION > 3)
#warning "版本过高"
#endif
int main()
{
int n = 1;
printf("版本=%d\n", VERSION);
}
gcc error.c -DVERSION=2
本文展示了一个使用预编译指示符的C语言程序示例。该程序通过`#error`和`#warning`指令根据定义的版本号发出错误和警告消息。此示例有助于理解如何在编译阶段进行条件编译和错误处理。
error.c
#include <stdio.h>
#if(VERSION < 3)
#error "版本过低"
#elif (VERSION > 3)
#warning "版本过高"
#endif
int main()
{
int n = 1;
printf("版本=%d\n", VERSION);
}
gcc error.c -DVERSION=2
401
166
366
6544
2507

被折叠的 条评论
为什么被折叠?