Why are pointers to inline functions allowed?

前端 未结 5 961
别跟我提以往
别跟我提以往 2021-01-31 02:12

I have two questions:

1) Why are pointers to inline functions allowed in C++? I have read that the code of inline functions just gets copied to the function call stateme

5条回答
  •  生来不讨喜
    2021-01-31 02:21

    Inline functions are not always inlined. It just signals that the programmer would like this function to be inlined. The compiler is allowed to inline any function, regarless of whether inline keyword was used or not.

    If the address of function is used, the function is most likely not inlined in the final executable, at least in GCC:

    When a function is both inline and static, if all calls to the function are integrated into the caller, and the function's address is never used, then the function's own assembler code is never referenced.

    GCC documentation

提交回复
热议问题