I recently encountered a codebase that favors the use of macros over extern inline functions. The language used here is C99, and the specific implementation is particularly performance sensitive (and so the argument given for the use of macro's is to avoid function calls / stack frame setup for frequently invoked functions).
As an improvement to readability, I've suggested that macro's be removed in favor of extern inline functions. For example, instead of:
#define FooBar(_AnArg, _AnotherArg) \ { \ if (_AnotherArg) \ { \ ... \ } \ else \ { \ ... \ } \ } I'm suggesting:
extern inline void FooBar(void* anArg, bool anotherArg) { ... } Looking over the generated assembly my function appears to be properly inlined and is therefore just as efficient as the macro while being easier to read and debug.
Is there any consideration of function inlining I am overlooking? Are there other benefits to macro use that I am not considering?
extern inline. Define itinlineandexternit normallyexternit normally” mean? Why make an inline functionexternat all instead ofstatic?