编译器指令不起作用 [英] Compiler Directives Not Working

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

问题描述

在VS 2003中工作。

头文件中的



[test.h]


#ifdef _UNUSED_NAME_3223458 //这个在任何时候都没有定义

#define TEST123 6789

#endif


实现文件中的



[test.cpp]


\\ TEST123的值将是6789或分配给它的任何值

即使_UNUSED_NAME_3223458从未定义且不存在

in any other文件。


[\ test.cpp]


另外,如果你这样做:

#ifndef _UNUSED_NAME_3223458

#define TEST123 0

#endif


在另一个之前插入此项(因此您在<之前测试未定义

定义),TEST123的值为0而不是6789.


没有错误或警告。


这几乎就像你测试的变量一样(_UNUSED_NAME_3223458

是从来没有在任何时候定义过)当你在测试它的时候处于未知状态。


这里发生了什么?

Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.

[\test.cpp]

Also, if you do:
#ifndef _UNUSED_NAME_3223458
#define TEST123 0
#endif

Insert this prior to the other one(so you test for not defined before
defined), TEST123 will have a value of 0 and not 6789.

No errors or warnings.

It is almost as if the variable you testing( _UNUSED_NAME_3223458 which
is never defined at any time) is in an unknown state at the time you
test it.

What is going on here?

推荐答案

sh ***** ******@gmail.com 写道:
在VS 2003中工作。


也许你应该问''微软。 public.vc.language''...

在一个头文件中:

[test.h]

#ifdef _UNUSED_NAME_3223458 //这个在任何时候都没有定义
#define TEST123 6789
#endif





在实现文件中:

[test.cpp]

\\ TEST123的值将是6789或分配给它的任何值
即使_UNUSED_NAME_3223458从未定义过,也不是在任何其他文件中呈现



通过_definition_如果''TEST123'具有值6789(或其他),则意味着

''TEST123''被定义_elsewhere_ *以及*这里,或者

" _UNUSED_NAME_3223458"宏实际上是_defined_,这就是C ++

预处理器如何定义''TEST123'。


你想要怀疑的是什么这是

预处理器的基本功能。我是_sure_这是你犯了错误的人。你确定

它是'ifdef"而不是ifndef?...

[\ test.cpp]

如果你这样做:
#ifnf _UNUSED_NAME_3223458
#define TEST123 0
#endif

在另一个之前插入此项(因此在
定义之前测试未定义),TEST123的值为0而不是6789 。

没有错误或警告。

几乎就像你测试的变量(_UNUSED_NAME_3223458,
从未在任何时间定义)处于未知状态当时你要测试它。

这里发生了什么?
Working in VS 2003.
Perhaps you should ask in ''microsoft.public.vc.language''...
in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.
By _definition_ if ''TEST123'' has the value 6789 (or whatever), it means
that either ''TEST123'' is defined _elsewhere_ *as well* as here, or that
"_UNUSED_NAME_3223458" macro is in fact _defined_ and that''s how the C++
preprocessor knows to define ''TEST123".

What you''re trying to doubt here is the very basic functionality of the
preprocessor. I am _sure_ it''s you who''s made the mistake. Are you sure
it''s "ifdef" and not "ifndef"?...

[\test.cpp]

Also, if you do:
#ifndef _UNUSED_NAME_3223458
#define TEST123 0
#endif

Insert this prior to the other one(so you test for not defined before
defined), TEST123 will have a value of 0 and not 6789.

No errors or warnings.

It is almost as if the variable you testing( _UNUSED_NAME_3223458 which
is never defined at any time) is in an unknown state at the time you
test it.

What is going on here?




无法说出来。你的代码片段没有足够的信息。

你要求从这些片段到概念的一个相当大的飞跃

其他一切都没问题,你没有不知怎的,搞砸了。我宁愿

相信编译器。


V

-

请删除资本来自我在邮寄回复时的地址



Impossible to say. Your code fragments do not carry enough information.
You''re asking for a rather big leap from those fragments to the notion
that everything else is OK, and you didn''t screw up somehow. I''d rather
believe the compiler.

V
--
Please remove capital As from my address when replying by mail


sh ***********@gmail.com 写道:
在VS 2003中工作。

在头文件中:

[test.h]

#ifdef _UNUSED_NAME_3223458 //这在任何时候都没有定义


_UNUSED_NAME_3223458保留给实现。您不能在代码中使用



#define TEST123 6789
#endif
Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
_UNUSED_NAME_3223458 is reserved to the implementation. You can''t use
it in your code.
#define TEST123 6789
#endif



2006年2月8日星期三09:00:48 -0800,shane.tietjen写道:
On Wed, 08 Feb 2006 09:00:48 -0800, shane.tietjen wrote:
在VS 2003工作。

在头文件中:

[test.h]

#ifdef _UNUSED_NAME_3223458 //这在任何时候都没有定义
#define TEST123 6789
#endif

[\ test.h]

在实施文件中:

[test.cpp]
\\ TEST123的值将是6789或分配给它的任何值
即使_UNUSED_NAME_3223458从未被定义且在任何其他文件中不存在
Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.




在test.h中的#ifdef之前放入


#undef _UNUSED_NAME_3223458

如果修复它,那么

_UNUSED_NAME_3223458定义*某处*。 (预处理器可能在

项目设置中定义了吗?)


此外,如果将其更改为


怎么办? #ifdef _UNUSED_NAME_3223458foo


?它的行为是否仍然相同?


- Jay



Put

#undef _UNUSED_NAME_3223458

right before the #ifdef in test.h. If that fixes it, then
_UNUSED_NAME_3223458 is defined *somewhere*. (Preprocessor defines in the
project settings perhaps?)

Also, what if you change it to

#ifdef _UNUSED_NAME_3223458foo

? Does it still behave the same?

- Jay


这篇关于编译器指令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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