How will i know whether inline function is actually replaced at the place where it is called or not?

前端 未结 10 760
长发绾君心
长发绾君心 2020-11-27 16:17

I know that inline function are either replaced where it is called or behave as a normal function.

But how will I know whether inline function is actually replaced a

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 17:00

    Above answer are very mush useful, I am just adding some point which we keep in our mind while writing inline function.

    Remember, inlining is only a request to the compiler, not a command. Compiler can ignore the request for inlining. Compiler may not perform inlining in such circumstances like:

    1) If a function contains a loop. (for, while, do-while)

    2) If a function contains static variables.

    3) If a function is recursive.

    4) If a function return type is other than void, and the return statement doesn’t exist in function body.

    5) If a function contains switch or goto statement.

    Complete info: https://www.geeksforgeeks.org/inline-functions-cpp/

提交回复
热议问题