Macros don’t have any impact on whether something’s computed at compile time or not.
The macro system is just a glorified copy-paste machine.
It’s entirely up to the compiler whether something is computed at compile time and it will make that decision regardless of whether you use macros or not.
When working on Dark & Under I found that replacing the
abs macro with a template function resulted in smaller code because the expansion of the
abs macro produced an expression that was either too complex for the compiler to properly optimise or that the compiler couldn’t optimise for legal reasons.
(I would expect a non-template function specialised for the types involved would have had the same result or smaller code.)
When you say ‘using C’ do you mean “the subset of C++ that resembles C” or actual C?
Because behaviour will differ depending on whether you’re using
.c files or
(And if you’re mixing
.cpp files then sometimes the compiler will start behaving awkwardly (as I found out recently).)
If you’re using the “common subset of C and C++” then I think I know what your problem is, and it’s down to how the
inline keyword behaves differently in C++ to how it does in C.
If you’re using actual C then this SO answer may or may not help solve your problem.