literal constant vs variable in math library

前端 未结 4 737
终归单人心
终归单人心 2020-12-03 19:34

So, I know that in C you need to link the code to the math library, libm, to be able to use its functions. Today, while I was trying to demonstrate

4条回答
  •  醉话见心
    2020-12-03 20:19

    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.

提交回复
热议问题