是否有预处理器定义来区分gcc和g ++代码?

nnd*_*wan 4 c c++ gcc g++

是否在gcc和g ++编译器中定义了预处理器宏,以便如果我想将C代码链接到C标准库或C++标准库?就像是:

someFile.c

#ifdef __CPP__
   #include <c++ library include>
#else
   #include <c library include>
Run Code Online (Sandbox Code Playgroud)

我确信有一个快速的谷歌搜索没有立即指出我,我相信有人会发布重复的问题,但无论如何,请指出我正确的方向.

Pra*_*ras 10

在c ++中你可以

#ifdef __cplusplus
Run Code Online (Sandbox Code Playgroud)

例如,如果c ++代码您希望编译器将某些代码作为c代码处理,则需要将该块放入

#ifdef __cplusplus
   extern "C" {
#endif

#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)


小智 5

我不确定#defineGCC 是否具体,但C++标准定义了符号__cplusplus.如果存在,那么您使用的是C++编译器.