该编译器照顾无用codeS一样,如果(0)? [英] Does the compiler take care the useless codes like if(0)?

查看:97
本文介绍了该编译器照顾无用codeS一样,如果(0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在编译的ffmpeg codeS windows下使用英特尔编译器VS2010。
对于以下codeS:

Recently, I am compiling the ffmpeg codes under windows use the VS2010 with intel compiler. For the following codes:

void ff_dcadsp_init(DCADSPContext *s)
{
    s->lfe_fir = dca_lfe_fir_c;
    if (ARCH_ARM) ff_dcadsp_init_arm(s);
}

ARCH_ARM 定义为 0

当我编译它在Linux下,没有在 ff_dcadsp_init_arm()目标文件中没有的功能,同时它在Windows下?所以,我要确保,如果编译器会做一些无用的codeS和如何设置英特尔编译器的。

When I compile it under linux, there is no function in ff_dcadsp_init_arm() in the object file, while it does under windows? So I want to make sure if the compiler will do something about the useless codes and how to set it for INTEL compiler.

推荐答案

通常情况下,大多数编译器能够采取那种在死者的code的护理,有效去除特定的指令/块。不过,据我所知是没有的保证的并可能编译器和/或提供的优化级别设置不同的。

Usually, most compilers are capable of taking care of that kind of the dead code, effectively removing that particular instruction / block. However, AFAIK it is not guaranteed and may differ between compilers and / or supplied optimization level settings.

然而,如果你希望它在preprocessing国家本身进行处理(应该是一个更好的方法,恕我直言,如 ARCH_ARM 是一个宏),你可以使用的#如果 preprocessor声明,以消除编译器优化级别的依赖性。

However, if you want this to be handled in the preprocessing state itself (should be a better approach, IMHO, as ARCH_ARM is a MACRO), you can make use of #if preprocessor statements, to remove the dependency on compiler optimization level.

例如,在一般

void ff_dcadsp_init(DCADSPContext *s)
{
    //something common code

    #if ARCH_ARM                 //this {#if...#endif} block 
        ff_dcadsp_init_arm(s);   //only get compiled if ARCH_ARM evaluates to non-zero
    #endif

   //something more common code
}

这篇关于该编译器照顾无用codeS一样,如果(0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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