C ++ #define预处理器 [英] C++ #define preprocessor

查看:183
本文介绍了C ++ #define预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道C ++中的#define指令是否声明全局标签?



我使用Visual Studio 2008(猜测是否重要)

解决方案

不,仅在当前翻译单位。



每个具有 #define 的文件,或包含具有 #define 的文件将看到定义。



编辑,以回应您的评论:在每个文件中获取一个定义,或者将其放在一个包含在任何地方的标题中,或者使用一些编译器选项来添加定义。 / p>

例如对于gcc,会执行

  gcc -Dthedefine = itsvalue 

不知道如何在VC ++中指定这样的内容,但我相信它可能以某种方式。


I need to know that does the #define directive in C++ declares global label? By global I mean visible in every file?

I'm using Visual Studio 2008, (guess if that matters)

解决方案

No, only in the current translation unit.

I.e. every file which has #define, or includes a file that has the #define will see the definition.

Edit, to respond to your comment: to get a define in every file, either put it in a header which gets included everywhere, or use some compiler option to get defines added.

e.g. for gcc one would do

gcc -Dthedefine=itsvalue

Not sure how one specifies such includes in VC++, but I'm sure it's possible somehow.

这篇关于C ++ #define预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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