ç多行宏观问题:为什么不使用if(1){...},而不是做{...}而(0)在多行宏定义 [英] C multi-line macro issue: why not use if(1){...} instead of do{...}while(0) in multi-line macro definition

查看:173
本文介绍了ç多行宏观问题:为什么不使用if(1){...},而不是做{...}而(0)在多行宏定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要调用多行宏循环中断/继续吧。

I want to invoke multi-line macro in circulation to break/continue it.

如果我使用do {...}而(0),在多行宏定义,打破/继续仅仅是对做{...}而(0),而不是循环调用谁该宏。所以我考虑使用如果(1){...}在多宏定义。

If I use "do{...}while(0)" in multi-line macro definition, break/continue is only effect on "do {...}while(0)", not the circulation who invoke this macro. So I consider using "if(1){...}" in multi-macro definition.

#define EXIT_CIRCULATION() \
        if(1){ \
           break; \
        }

void func(){
    while(1){
       ...
       EXIT_CIRCULATION();
       ...
    }
}

但我怀疑wheather它是用如果(1){...}在宏定义,因为我无法找到任何互联网例如一个很好的方式。

But I doubt wheather it is a good way to use "if(1){...}" in macro definition, because I can not find any example in internet.

谢谢!

推荐答案

如果您code像

 if (somecondition)
    EXIT_CIRCULATION();
 else
    break;

那么您的宏的扩展将不会像你期望直观。在其他将适用于你的如果(1),将永远不会发生。

then the expansion of your macro won't behave as you intuitively expect. The else would apply to your if (1) and will never happen.

这篇关于ç多行宏观问题:为什么不使用if(1){...},而不是做{...}而(0)在多行宏定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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