执行“#if 0”内的代码 [英] Executing code inside "#if 0"

查看:121
本文介绍了执行“#if 0”内的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些C / C ++代码块放在

#if 0


#end如果

有没有无论如何要使这些块中的代码执行

(可能是通过使用一些命令行选项)?

我正在使用SUN编译器。

There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?
I am using SUN compiler.

推荐答案



qazmlp写道:


qazmlp wrote:

有一些C / C ++块代码放在
#if 0

#end如果

无论如何都要使这些块中的代码被执行
(可能是使用一些命令行选项)?

我正在使用SUN编译器。

There are some blocks of C/C++ code put under
#if 0

#end if

Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?

I am using SUN compiler.




编号虽然它在那里所附的代码将被忽略编译器,

所以可执行文件中没有任何内容可以执行。要运行代码,你需要在没有#if 0的情况下重新编译程序,或者在

之后将其更改为#if 01之类的代码。


John Howells



No. While it is there the enclosed code will be ignored by the compiler,
so there is nothing in the executable to execute. To run the code you
will have to recompile the program without the "#if 0", or after
changing it to something like "#if 01".

John Howells


文章< db **************** *********@posting.google.com> ,

qazmlp< qa ******** @ rediffmail.com>写道:
In article <db*************************@posting.google.com> ,
qazmlp <qa********@rediffmail.com> wrote:
有一些C / C ++代码块放在
#if 0

#end如果

无论如何使这些块中的代码执行
(可能通过使用一些命令行选项)?
There are some blocks of C/C++ code put under
#if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?




为什么使用#if 0 ;如果您认为它是一个选项,您可以在编译时选择
吗?把它更改为:


#if调试

....

#endif

然后你可以在编译时使用-DDEBUGGING = 1来启用那个块。


-

Barry Margolin, ba ************ @ level3.com

Level(3),Woburn,MA

***不要直接向我发送技术问题,将它们发布到新闻组。

请不要复制对我的跟进 - 我会假设它没有发布到小组。



Why did you use "#if 0" if you meant for it to be an option you could
select at compile time? Change it to something like:

#if DEBUGGING
....
#endif

and then you can use -DDEBUGGING=1 when compiling to enable that block.

--
Barry Margolin, ba************@level3.com
Level(3), Woburn, MA
*** DON''T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON''T copy followups to me -- I''ll assume it wasn''t posted to the group.


周五,2003年7月11日16:21:04 +0200,Barry Margolin写道:
On Fri, 11 Jul 2003 16:21:04 +0200, Barry Margolin wrote:
在文章< db ************************* @ posting.google中。 COM> ,qazmlp
< qa ******** @ rediffmail.com>写道:
In article <db*************************@posting.google.com> , qazmlp
<qa********@rediffmail.com> wrote:
有一些C / C ++代码块放在#if 0

#end如果

无论如何都要编写代码在这些块中执行
(可能是通过使用一些命令行选项)?
There are some blocks of C/C++ code put under #if 0

#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?



为什么使用#if 0?如果你认为它是一个选项,你可以在编译时选择?把它更改为:

#if调试
...
#endif

然后你可以在编译时使用-DDEBUGGING = 1启用该块。



Why did you use "#if 0" if you meant for it to be an option you could
select at compile time? Change it to something like:

#if DEBUGGING
...
#endif

and then you can use -DDEBUGGING=1 when compiling to enable that block.



这是一件好事,你甚至可以更进一步使用

使用断言宏调用所使用的符号NDEBUG。

在最终/生产版本中,设置了-DNDEBUG。


That''s a good thing, you even can go further and use
use the symbol NDEBUG as used by the assert macro calls.
In a final/production build, -DNDEBUG is set.


这篇关于执行“#if 0”内的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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