Prefer writing and using
real functions to
function-like macros. While it might be tempting to write and use
function-like macros instead of
functions, this might not be a good choice for the following reasons:
Macros can cause side effects.
No type checking is performed.
Macros are preprocessed, not compiled.
They do not check compiler errors and are harder to debug.
Consider the following example, which uses a
macro-like function to square a given parameter:
#define SQR(a) ((a) * (a))
int main(void)
{
int x = 1;
int result = SQR(++x); ...