c code #define MAX(a, b) ((a)>(b)?(a):(b))
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
如果a,b分别是单个变量,没什么区别,如果是a,b本身是表达式,前者可以避免一些歧义引起的潜在错误。
例子留给楼下。 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
页:
[1]