#限定 [英] #define

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

问题描述

我使用#define预处理器指令定义了一些变量。

后来我检查了我是否定义了一个变量。有时

即使定义了一个变量,#if!defined(var)construct

返回true。我在SunOS8上使用gcc3.0.1。我很感激

如果有人能告诉我这是一个错误还是我在做什么

错误。


tia ,

Srinivas

I have defined some variables using #define preprocessor instruction.
And then later I checked whether I had defined a variable. Sometimes
even though a variable have been defined, #if !defined(var) construct
is returning true. I am using gcc3.0.1 on SunOS8. I would appreciate
if any body can tell me whether this is a bug or I am doing something
wrong.

tia,
Srinivas

推荐答案

srinivas reddy< sr ************* @ yahoo.com>在消息中写道

news:ff ************************** @ posting.google.c om ...
srinivas reddy <sr*************@yahoo.com> wrote in message
news:ff**************************@posting.google.c om...
我使用#define预处理器指令定义了一些变量。
后来我检查了我是否定义了一个变量。有时候即使定义了变量,#if!defined(var)构造
也会返回true。我在SunOS8上使用gcc3.0.1。我很感激
如果有任何身体可以告诉我这是一个错误还是我做错了什么。
I have defined some variables using #define preprocessor instruction.
And then later I checked whether I had defined a variable. Sometimes
even though a variable have been defined, #if !defined(var) construct
is returning true. I am using gcc3.0.1 on SunOS8. I would appreciate
if any body can tell me whether this is a bug or I am doing something
wrong.




我会说这肯定是一个错误,但我不会把任何东西放在C ++预处理器之外。


难以置信,#if var1 == var2只是转换var1和var2到0

(是的,0,即使预处理器是一个_text_替换器)如果它没有
遇到定义的他们(像Basic这样的东西,假设任何它所遇到的任何未定义的变量必须是一个int;而我认为C ++摆脱了这个隐含的
并隐含了因为他们被认为不安全的)。 0 == 0

当然是真的。


我只能假设那些有影响力的人希望看到
结束
预处理器总是试图通过确保

尽可能地工作来加速其死亡。


DW


David White写道:
David White wrote:

我只能假设有影响力的人希望完全看到
预处理器的结束我们试图通过确保它尽可能地工作来加速它的死亡。

I can only assume that those with influence who wish to see the end of the
preprocessor altogether are trying to accelerate its death by ensuring that
it works as badly as possible.




然后它必须是那些最初提出这个想法的人三十年前的预处理器试图加速它的死亡,因为

用算术表达式中的0替换未定义的符号已经是自b / b
规则以来开始。


-


Pete Becker

Dinkumware,Ltd。( http://www.dinkumware.com




" srinivas雷迪" < SR ************* @ yahoo.com>在消息中写道

news:ff ************************** @ posting.google.c om ...

"srinivas reddy" <sr*************@yahoo.com> wrote in message
news:ff**************************@posting.google.c om...
我使用#define预处理器指令定义了一些变量。
后来我检查了我是否定义了一个变量。有时候即使定义了变量,#if!defined(var)构造
也会返回true。我在SunOS8上使用gcc3.0.1。我很感激
如果有任何身体可以告诉我这是一个错误还是我做错了什么。

tia,
Srinivas
I have defined some variables using #define preprocessor instruction.
And then later I checked whether I had defined a variable. Sometimes
even though a variable have been defined, #if !defined(var) construct
is returning true. I am using gcc3.0.1 on SunOS8. I would appreciate
if any body can tell me whether this is a bug or I am doing something
wrong.

tia,
Srinivas




也许你已经定义了这个变量,但是你的#if语句写的是

中的编译单元吗?换句话说,如果您在unit1.h中#define

变量,并在unit2.cpp中进行检查,那么您需要添加

#include" unit1 .H"在检查变量是否存在之前在unit2.cpp中。


(我通常将我的#define'放在预编译的头文件中,如果它们将是

在我的项目中广泛使用。但这与CodeWarrior有关......我不知道如何使用gcc

所以它可能会有所不同。)


只是想一想......


-Howard



Perhaps you have defined the variable, but not in the compilation unit in
which your #if statement is written? In other words, if you #define the
variable in unit1.h, and make your check in unit2.cpp, then you need to add
#include "unit1.h" in unit2.cpp before checking if the variable exists.

(I usually put my #define''s in a precompiled header if they''re going to be
widely used in my projects. But that''s with CodeWarrior...I don''t know how
to use gcc so it may be different.)

Just a thought...

-Howard


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

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