Simple question: When the compiler faces a call to, say, pow() with two constants (i.e. values from macros), is it optimized by evaluating it at compile time, or is it still calculated at run-time?
Example:
#define V_BITMEM_GRID 3
#define V_BITMEM_TOTAL pow(V_BITMEM_GRID,2)
Thanks!
EDIT If not, is there a way to calculate the square/cube of a macro as another macro (like I’m attempting above) at compile-time?
It can be both. It depends on how intrusive the compiler is, whether it has access to the function implementation and can correctly evaluate it. There’s no rule that specifies how it’s supposed to be, as long as observed behavior is the same.
For example, I got the following:
The function, as you can see, isn’t even called. So it is possible that the call is eliminated for good.