cls*_*udt 7 c++ macros c-preprocessor
我需要在C++项目中包含一些最初用C编写的头文件.在头文件中,使用restrict关键字,这导致C++的语法错误.
我正在寻找一个预处理器宏,它检查我是否正在使用C++编译器进行编译,并restrict在这种情况下删除关键字.
Dan*_*her 10
#ifdef __cplusplus
#define restrict
#endif
Run Code Online (Sandbox Code Playgroud)
应该这样做.restrict在C++中不是一个关键字,所以#define在那里没有问题是没有问题的.
或者,正如Arne Mertz建议的那样,更好的是
extern "C" {
#define restrict
// include C headers here
#undef restrict
}
Run Code Online (Sandbox Code Playgroud)
在C++源代码中包含C头的位置.