C++技巧之五

 
 
   
   
 
   
   
 
   
   
// Original do/while Macro 
   
   
//原始的do/while
  
  
 
   
   
#define MY_ASSERT_ONE(x) do { /
   
   
                    if (!(x)) {/
   
   
                                       _asm int 3 /
   
   
                    } /
   
   
                    }  while(0)
   
   
 
   
   
// new Macro that removes the loop 
   
   
// 新宏移去了loop
   
   
 
   
   
#define MY_ASSERT_ONE(x) { /
   
   
                    if (!(x)) {  /
   
   
                                         _asm int 3  /
   
   
                    } /
   
   
                    }
   
   

 

代码清单 4 避免一个编译器错误
 
   
   
(a). /* This code will cause a compile error */
   
   
/* 此段代码将产生一个编译器错误 */
   
   
void main(void)
   
   
{
   
   
                    int i = 10;
   
   
                   printf("i: %d/n", i);
   
   
                    int j = 100;  /* This statement will cause a compiler error since
   
   
                                            it was not declared at the top of the function. */
   
   
/* 此语句将导致一个编译器错误,
  
  
因为它未在函数顶部声明过。 */
   
   
 
   
   
                    printf("j: %d/n", j);
   
   
}
   
   
 
   
   
(b). /* whereas this code will not */
   
   
/*而此段代码将不产生一个编译器错误*/
   
   
void main(void)
   
   
{
   
   
                    int i = 10;
   
   
                    printf("i: %d/n", i);
   
   
                    {
   
   
                                         int j = 100;            /* This statement is fine since it is akin
   
   
                                                                                 to defining a local function within the function.  */
   
   
/* 此语句很精炼,
  
  
因为它在函数中定义了一局部函数的同族。*/
   
   
                                         printf("j: %d/n", j);
   
   
                    }
   
   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值