如何检查(通过预处理器)是否将C源文件编译为C ++代码 [英] How to check (via the preprocessor) if a C source file is being compiled as C++ code

查看:117
本文介绍了如何检查(通过预处理器)是否将C源文件编译为C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题标题应该说明一切,但以下是我正在寻找什么样的事情的示例:

  #ifndef THE_IDENTIFIER_THAT_WOULD_INDICATE_BEING_COMPILED_AS_CPLUSPLUS 

/ *
*重要事例。
* /
typedef enum _bool bool;
enum _bool {false,true};

#endif

标识符是什么?它是严重的窃听我,因为我知道我以前见过的代码。



顺便说一下,我使用GCC。



(我很惊讶我在SO的某个地方找不到重复的东西,如果其他人可以找到它的话,请随意重定向我并将其作为重复项来关闭。)

解决方案

  #ifndef __cplusplus 

如果我没有记错的话。

The question title should say it all, but here's an example of what sort of thing I'm looking for:

#ifndef THE_IDENTIFIER_THAT_WOULD_INDICATE_BEING_COMPILED_AS_CPLUSPLUS

/*
 * Example of something that would matter.
 */
typedef enum _bool bool;
enum _bool { false, true };

#endif

What is the identifier? It's bugging me severely, as I know I've seen code that does this before.

I'm using GCC, by the way.

(I'm surprised I couldn't find a duplicate somewhere on SO. If someone else can find one, feel free to redirect me and close this as a dupe.)

解决方案

#ifndef __cplusplus

If I remember correctly.

这篇关于如何检查(通过预处理器)是否将C源文件编译为C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆