__cplusplus介绍

伪代码如下:

#ifdef __cplusplus
extern "C" {
    
    
#endif
#include <....h>
#ifdef __cplusplus
}
#endif

如果在C的编译环境中,代码就变成了:

#include <....h>

如果在C++环境中,代码就变成了:

extern "C" {
    
    
#include <....h>
}

这个__cplusplus在编译器中被定义,不同的C++版本有不同的值。
C++03:__cplusplus = 199711L
C++11:__cplusplus = 201103L
所以编译是否使用C++11,可以进行如下定义:

#if __cplusplus < 201103L
       #error “Should use –std=c++11 option for compile
#endif

猜你喜欢

转载自blog.csdn.net/weixin_43466192/article/details/123223702