【发布时间】:2012-07-19 03:47:49
【问题描述】:
假设我在 foo.h 中定义了 BAR。但是 foo.h 可能不存在。我如何包含它,而不会让编译器抱怨我?
#include "foo.h"
#ifndef BAR
#define BAR 1
#endif
int main()
{
return BAR;
}
因此,如果 BAR 在 foo.h 中定义为 2,那么如果 foo.h 存在则程序将返回 2,如果 foo.h 不存在则返回 1。
【问题讨论】:
-
提供你自己定义
BAR的后备foo.h,并相应地配置编译器的搜索路径? -
我想我可以做到。为什么后备 foo.h 需要包含任何内容?
标签: c gcc include header-files