literal constant vs variable in math library

GCC can do constant folding for several standard-library functions. Obviously, if the function is folded at compile-time, there is no need for a run-time function call, so no need to link to libm. You could confirm this by taking a looking at the assembler that the compiler produces (using objdump or similar).

I guess these optimizations are only triggered when the argument is a constant expression.

Leave a Comment