I had tried to debug but no luck I can\'t understand why the second printf() is call increment() thrice but the first one call twice as expected.
#include &l
Use of macros is highly "dangerous": all sort of strange things can happen. For instance, in your case, if you call MAX( f(), g() )
the function which gives you the greatest result gets called twice, the other one gets called just once. Since you are using MAX(x, f())
, f
gets called twice if and only if it gives a result which is greater than x
.
In particular, the macro expands as
( (x) > (increment())? (x):(increment()) )
so that if the condition (testing which requires one evaluation of increment()
, increment()
gets executed in order to produce the result.