#ifndef C · 预处理
如果指定的宏名字还没有被定义,就保留它和对应 #endif 之间的代码参与编译。
怎么用
#ifndef 宏名 代码 #endif
小例子
#include <stdio.h>
#ifndef VERSION
#define VERSION 1
#endif
int main(void) {
printf("%d", VERSION);
return 0;
}
运行结果
输出 1
提醒:头文件保护里常用它防止同一个头文件被重复包含
官方文档:https://en.cppreference.com/w/c/preprocessor/conditional
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条