开发者

Macro with zero arguments - with or without parentheses

开发者 https://www.devze.com 2023-04-07 17:19 出处:网络
When defining macro with zero arguments we can define it with parentheses, thus looking more like function开发者_StackOverflow社区 or without parentheses.

When defining macro with zero arguments we can define it with parentheses, thus looking more like function开发者_StackOverflow社区 or without parentheses.

What is preferable (probably there's no right answer) way of doing it?


As a general rule, I would expect MACRO() to generate executable code, which may have side-effects. I use MACRO (sans parentheses) for more structural things that yield declarations, boilerplate, or constants.


If you intend to create a macro that mimics a function, then use the () version. Otherwise don't.


Yes, we can and I don't think that there's really any particular technical reason why one is better than the other. However, conventionally we would omit the () where not required.

0

精彩评论

暂无评论...
验证码 换一张
取 消