嗨,为什么我不能在宏观中使用#if? [英] hi why can not i us #if in the macro?

查看:65
本文介绍了嗨,为什么我不能在宏观中使用#if?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


下面宏的问题是什么?


#define COMMENT_LINE(p)\

#if 0 \

(p); \

#endif


当我在vs.net编译它,它抱怨


c99.cpp(12):错误C2162:需要宏的正式游侠

c99.cpp(17) :错误C2059:语法错误:常量

c99.cpp(17):错误C2065:" endif" :未申报的符号

我不知道为什么。

hi all,

what''s the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif

when i compiled it in vs.net, it complains

c99.cpp(12) : error C2162: formal paramer of macro needed
c99.cpp(17) : error C2059: syntax error : "constant"
c99.cpp(17) : error C2065: "endif" : undeclared symbol
i don;t know why.

推荐答案

" baumann @ pan" < BA ********* @ gmail.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...
"baumann@pan" <ba*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
下面宏的问题是什么?

#define COMMENT_LINE(p)\
#if 0 \
(p); \
#endif
what''s the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif




您不能在#define中使用预处理程序指令。这就是定义语言的方式

。如果你解释一下你想要实现的目标,

也许有人可以建议另一种解决方案。


Alex



You cannot use preprocessor directives in a #define. That is just the way
the language is defined. If you explain what you are trying to achieve,
maybe someone can suggest an alternative solution.

Alex

在文章< 11 ********************** @ z14g2000cwz.googlegroups .com> ;,

baumann @ pan < BA ********* @ gmail.com>写道:
In article <11**********************@z14g2000cwz.googlegroups .com>,
baumann@pan <ba*********@gmail.com> wrote:
下面宏的问题是什么?

#define COMMENT_LINE(p)\
#if 0 \
(p); \
#endif
what''s the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif




你似乎期待宏扩展成包含
$ b的东西$ b #if指令,但它不会那样工作。


首先将线条粘贴在一起,制作


#定义COMMENT_LINE(p)#if 0(p);#endif


这在语法上是不正确的。


- Richard



You seem to be expecting the macro to expand into something containing
the #if directive, but it doesn''t work like that.

The lines are pasted together first, producing

#define COMMENT_LINE(p) #if 0 (p);#endif

which is syntactically incorrect.

-- Richard


baumann @ pan在11/04/05写道:
baumann@pan wrote on 11/04/05 :
下面宏的问题是什么?

#定义COMMENT_LINE(p)\
#if 0 \
(p); \
#endif


这不是C.你在宏中不能有预处理器东西(#是

已用于其他东西)。

当我在vs.net中编译它时,它会抱怨

c99.cpp(12):错误C2162:需要宏的正式paramer
what''s the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif
This is not C. You can''t have proprocessor thingies in macros (# is
already used for something else).
when i compiled it in vs.net, it complains

c99.cpp(12) : error C2162: formal paramer of macro needed




如果你打算编译C源,你的扩展名应该是.c。


-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

C库:< a rel =nofollowhref =http://www.dinkumware.com/refxc.htmltarget =_ blank> http://www.dinkumware.com/refxc.html


C是一个尖锐的工具



Your extension should be .c if you intent to compile a C source.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"


这篇关于嗨,为什么我不能在宏观中使用#if?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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