| 网站首页 | 新闻快报 | 软件教程 | 硬件教程 | 设计学院 | Q Q 专区 | 编程开发 | 网络安全 | 
您现在的位置: 浩扬网络 >> 编程开发 >> VC C编程 >> 教程正文
C++技巧之五
作者:不详 文章来源:安全中国 点击数: 更新时间:2006-8-4 20:07:14

// 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);
                    }
}
【教程录入:残梦    责任编辑:残梦 】
发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
  • 上一篇教程:

  • 下一篇教程:
  • 网友评论:(评论内容只代表网友观点,与浩扬网络立场无关!)
    热门文章

    赞助商


    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 |