I was reading that in C++ using macros like
#define max(a,b) (a > b ? a : b)
can result in a \'double evaluation\'. Can someone give me
a
and b
occur two times in the macro definition. So if you use it with arguments that have side-effects, the side-effects are executed two times.
max(++i, 4);
will return 6 if i = 4
before the call. As it is not the expected behavior, you should prefer inline functions to replace such macros like max
.