条件编译“else" [英] Conditional compilation "else"

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

问题描述

在 AS3 中,您可以将常量传递给编译器

In AS3 you can pass a constant to the compiler

-define+=CONFIG::DEBUG,true

并将其用于条件编译,如下所示:

And use it for conditional compilation like so:

CONFIG::DEBUG {
   trace("This only gets compiled when debug is true.");
}

我正在寻找像 #ifndef 这样的东西,这样我就可以否定 debug 的值并使用它有条件地添加发布代码.到目前为止,我找到的唯一解决方案是在 adobe 的 条件编译文档 中,因为我的调试和发布配置是相互排斥的 我不喜欢同时拥有 DEBUG 和 RELEASE 常量的想法.

I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.

此外,这种格式有效,但我假设它在运行时运行检查,这不是我想要的:

Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:

if (CONFIG::DEBUG) {
   //debug stuff
}
else {
   //release stuff
}

我也考虑过做这样的事情,但它仍然不是我希望的优雅解决方案:

I also considered doing something like this but it's still not the elegant solution I was hoping for:

-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG

提前致谢:)

推荐答案

使用 if/else 结构:死代码将被编译器移除不在运行时进行测试.您的 swf 中将只有一个版本的代码.

Use the if / else construct : the dead code will be removed by the compiler and it will not be tested at runtime. You will have only one version of your code in your swf.

如果您不确定,请使用反编译器或转储工具来查看实际情况.

If you are not sure use a decompiler or a dump tool to see what really happens.

http://apparat.googlecode.com/files/dump.zip

http://www.swftools.org/

...

这篇关于条件编译“else"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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