x264 common\common.c “if(0);”的作用 及#define OPT(STR) else if( !strcmp( name, STR ) )

 // TEST1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>

int main(int argc, char* argv[])
{
 //printf("Hello World!\n");

 int i;
 i = 1;
 char *name;
 char *STR;
 name = "0";
 STR = "0";
 if (0)
 {
  printf("Hello World!\n");
 }


 #define OPT(STR,name) else if (!strcmp(STR,name))
 OPT("b","b") /*  else if (!strcmp(STR,name)) */
 {
  printf("-1-----------------------\n",STR);

  //printf("STR与name相等!\n",STR,name);
 }
 OPT("a","a") /*  else if (!strcmp(STR,name)) */
 {
  printf("-2-----------------------\n",STR);

  //printf("STR与name相等!\n",STR,name);
 }


  

 #define for if(1)for


 return 0;
}

 

   

以上代码运行结果:

x264 commoncommon.c define OPT(STR) else if( !strcmp( name, STR ) ) - 加菲 -  .
 

 如果把上述代码改一下:

x264 commoncommon.c define OPT(STR) else if( !strcmp( name, STR ) ) - 加菲 -  .
 
所以,在后续的部分,x264里的 if(0);应该就是这个原因吧。

 

x264 common/common.c

#define OPT(STR) else if( !strcmp( name, STR ) )

    if( (!strncmp( name, "no-", 3 ) && (i = 3)) || (!strncmp( name, "no", 2 ) && (i = 2)) ) /* ?i在这儿怎么会大于0呢? */
    {
        name += i;
        value = atobool(value) ? "false" : "true";
    }

 #define OPT(STR) else if( !strcmp( name, STR ) )  /* strcmp(const char *s1,const char * s2); 比较字符串s1和s2。 说明: 当s1<s2时,返回值<0 ; 当s1=s2时,返回值=0 ; 当s1>s2时,返回值>0 , 即:两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。 */
    if(0);
    OPT("asm")            
/* else if( !strcmp( name, "asm" ) )  */
        p->cpu = atobool(value) ? x264_cpu_detect() : 0; /*  */
    OPT("threads")           /*  */
    {
        if( !strcmp(value, "auto") )      /*  */
            p->i_threads = 0;
        else
            p->i_threads = atoi(value);
    }
    OPT("level")
    {
        if( atof(value) < 6 )
            p->i_level_idc = (int)(10*atof(value)+.5);
        else
            p->i_level_idc = atoi(value);
    }
    OPT("sar")
    {
        b_error = ( 2 != sscanf( value, "%d:%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) &&
                    2 != sscanf( value, "%d/%d", &p->vui.i_sar_width, &p->vui.i_sar_height ) );
    }
    OPT("overscan")
        b_error |= parse_enum( value, x264_overscan_names, &p->vui.i_overscan );
    OPT("vidformat")
        b_error |= parse_enum( value, x264_vidformat_names, &p->vui.i_vidformat );
    OPT("fullrange")
        b_error |= parse_enum( value, x264_fullrange_names, &p->vui.b_fullrange );
    OPT("colourprim")
        b_error |= parse_enum( value, x264_colorprim_names, &p->vui.i_colorprim );
    OPT("transfer")
        b_error |= parse_enum( value, x264_transfer_names, &p->vui.i_transfer );
    OPT("colourmatrix")
        b_error |= parse_enum( value, x264_colmatrix_names, &p->vui.i_colmatrix );

   

 

 

 

 

 

 

 

 

 

 

其它:

根据C++标准:
for(int   i   =   0;   i   <   5;   i   ++
{
    ...
}

i的作用域应该是在花括号内。而VC6不符合标准,i的作用域会一直持续到后面:
int   main()
{
    for(int   i   =   0;   i   <   5;   i   ++
    {
        cout   < <   i;//正确
    }
    cout   < <   i;//按照标准应该错误,但在VC6中正确
    int   i;//按照标准应该正确,但在VC6中是重定义错。
}

因此在VC6中通常定义这样一个宏,这个上面的语句在宏被展开时就成了:
if   (0)
else
    for(int   i   =   0;   i   <   5;   i   ++)
    ...

这样i的定义就不会“遗害后人”了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值