欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
C++技巧之五
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
  {域名已经过期}

 

 
 
 
// 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);
                    }
}
附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步