找回密码
 FreeOZ用户注册
查看: 1568|回复: 2
打印 上一主题 下一主题

[学习深造] c code #define MAX(a, b) ((a)>(b)?(a):(b))

[复制链接]
跳转到指定楼层
1#
发表于 3-8-2016 19:38:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册

x
I forgot what is the advantage of this macro #define MAX(a, b) ((a)>(b)?(a)b)) vs #define MAX(a, b) (a>b?a:b)

Thanks in advance
回复  

使用道具 举报

2#
发表于 4-8-2016 00:28:46 | 只看该作者
如果a,b分别是单个变量,没什么区别,如果是a,b本身是表达式,前者可以避免一些歧义引起的潜在错误。

例子留给楼下。
回复  

使用道具 举报

3#
发表于 4-8-2016 01:09:45 | 只看该作者
In this case it might be fine without the extra parentheses because precedence of ternary operator is after arithmetic operators.
http://en.cppreference.com/w/c/language/operator_precedence
回复  

使用道具 举报

您需要登录后才可以回帖 登录 | FreeOZ用户注册

本版积分规则

小黑屋|手机版|Archiver|FreeOZ论坛

GMT+11, 16-2-2025 06:24 , Processed in 0.012624 second(s), 18 queries , Gzip On, Redis On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表