Herbert Schildt says:
In some situations, real function should be used in place of function-like-macro, for example: where code size is to be minimize
Sometimes arguments have side effects.
For example, the value of i++
is i
, but i
is increased by 1. As a result, the value of next i++
will be i + 1
.
In a macro, arguments are evaluated every time it's called for, causing resulting values; In a function, the (actual) arguments are evaluated and copied to (formal) arguments inside the function, dismissing the side effects.
When inplementing a function, you don't care about side effects. However, implicit type promotion and casting may be error-prone instead.