私はデバッグしようとしましたが、2番目のprintf()がincrement()を3回呼び出すのに、最初のものは予想どおり2回呼び出す理由を理解できません。
#include <stdio.h>
#define MAX(a, b) ( (a) > (b) ? (a) : (b) )
int increment(){
static int i = 42;
i += 5;
printf("increment returns %d\n", i); // 47, 52, 57
return i;
}
int main( int argc, char ** argv ) {
int x = 50;
// parameters compute from right to left side
printf("max of %d and %d is %d\n",
x, //3rd: 50
increment(), //2nd: 52
MAX(x, increment()) //1st: 50,47 -> 50
);
printf("max of %d and %d is %d\n",
x, //3rd: 50
increment(), //2nd: 62
MAX(x, increment()) //1st: 50,57 -> 57
);
return 0;
}
結果
increment returns 47
increment returns 52
max of 50 and 52 is 50
increment returns 57
increment returns 62
increment returns 67
max of 50 and 67 is 62