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 at the place where it is called or not as decision of treating inline function as inline is at the compile time?
Programatically at run-time, You cannot.
And the truth of the matter is: You don’t need to know
An compiler can choose to
inlinefunctions that are not markedinlineor ignore functions marked explicitlyinline, it is completely the wish(read wisdom) of the compiler & You should trust the compiler do its job judiciously. Most of the mainstream compilers will do their job nicely.If your question is purely from a academic point of view then there are a couple of options available:
Analyze generated Assembly Code:
You can check the assembly code to check if the function code is inlined at point of calling.
How to generate the assembly code?
For gcc:
Use the
-Sswitch while compilation.For ex:
The generated assembly code is created as file
FileName.s.For MSVC:
Use the /FA Switch from command line.
In the generated assembly code lookup if there is a
callassembly instruction for the particular function.Use Compiler specific Warnings and Diagnostics:
Some compilers will emit a warning if they fail to comply an inline function request.
For example, in gcc, the
-Winlinecommand option will emit a warning if the compiler does not inline a function that was declared inline.Check the GCC documentation for more detail: