我已经开始阅读 Effective C++ 并且在第 2 项中的某个时间点,提到了以下内容:
// call f with the maximum of a and b
#define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b))
...
int a = 5, b = 0;
CALL_WITH_MAX(++a, b); // a is incremented twice
CALL_WITH_MAX(++a, b+10); // a is incremented once
在这里,在调用 f 之前 a 增加的次数取决于与之比较的对象!
确实,如果我在 中使用简单的打印语句f
,第一次调用会打印 7 ,但我终其一生都无法弄清楚原因。我错过了一些明显的东西吗?