在宏中执行{} while(0)与({})相比有什么优势? [英] Advantages of do { } while(0) versus ({ }) in a macro?

查看:58
本文介绍了在宏中执行{} while(0)与({})相比有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于在宏中使用do { ... } while(0)的问题,堆栈溢出有很多问题,但这有些不同.我知道为什么do { ... } while(0)用于在宏扩展中包装多行代码.但是我经常看到另一种形式:({ ... }).

There are plenty of questions on Stack Overflow regarding the use of do { ... } while(0) in macros, but this is a bit different. I understand why do { ... } while(0) is used to wrap multiple lines of code in a macro expansion. But there is another form I often see: ({ ... }).

({ })格式的优点是它是一个表达式,并且可以具有返回值". (主观地)它也比do { } while(0)读得更好.那么为什么不总是使用它呢?代替在宏中使用do { } while(0)有什么优势?

The ({ }) form has the advantage that it is an expression and can have a "return value". It also (subjectively) reads better than do { } while(0). So why isn't it always used? What advantage is there to using do { } while(0) in a macro instead?

推荐答案

因为({...}) 查看全文

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