Why can function pointers be `constexpr`?

前端 未结 4 2040
花落未央
花落未央 2021-02-03 22:31

How does the compiler know where in memory the square root will be before the program is executed? I thought the address would be different everytime the program is executed, bu

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-03 23:14

    How does the compiler know where in memory the square root will be before the program is executed?

    The tool chain gets to decide where it puts the functions.

    Is it because the address is relative to another address in memory?

    If the produced program is either relocatable or position independent then yes, that's the case. If the program is neither, then the address can even be absolute.

    Why would the exact same memory spots be available next time the program is run?

    Because the memory space is virtual.

提交回复
热议问题