我们在实际编写代码的时候,经常需要判断当前编译环境是否存在我们需要的头文件,如果不存在,则使用其他头文件代替。
以前这个操作都是通过外部的configure文件生成Makefile的时候指定。
最近的GCC已经增加了__has_include这个内置函数判断头文件是否存在。
这个功能最早是Clang实现的,现在GCC终于补上了这个功能。
例子如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
#ifdef __has_include # if __has_include(<optional>) # include <optional> # define have_optional 1 # elif __has_include(<experimental/optional>) # include <experimental/optional> # define have_optional 1 # define experimental_optional # else # define have_optional 0 # endif #endif |
Code Composer Studio 8.2.0.00007 ,GCC 5支持这个内置函数。