views:

114

answers:

6
+3  Q: 

Inline Functions

I know compiler may or may not perform inline expansion of a function whether requested by the programmer or not.
I was just curious to know, is there any way by which programmer can know for sure that compiler has inlined a particular function?

A: 

Read the disassembly of the object file.

dsimcha
+8  A: 

Other than by looking at the generated code, no. Some implementations may provide that information but it's not required by the standard.

Things like inline or register (shudder) are suggestions to the compiler and it's free to accept them, ignore them or even lie to you that it's done it while secretly going behind your back and not doing it :-)

I tend not to use features like that since I suspect the compiler often knows better than I do how to wring the most performance out of my code.

paxdiablo
+1  A: 

Set your compiler to generate assembler code and check there.

Glorphindale
And if you have different flags for debug v release builds, make sure to use the latter. I've seen some compilers that never inline unless you have at least some optimization enabled.
R Samuel Klatchko
+1  A: 

You can profile your code and see if the function of interest shows up in the call stack. Although, I suppose there is no guarantee if your stack sampling rate is not high enough.

But it may prove that it is inlined: if you know A calls B, which calls C, and A never calls C directly, if you see A calling C on the call stack, you know B was inlined for that call.

A: 

There is no way to know except to look at the output assembler.

Compilers these days are 'smart' and they decide what functions to inline and in what cases.

Just like the register keyword, compilers do the picking these days and really ignore your requests.

gbrandt
A: 

I don't think there is a way to find out what you want,

But you can increase the possibilites of the function being an inline function by,

Making the definition of the function visible to the translation unit in which it is called. i.e you always have to put the definition of an inline function in header file.

Vinod T. Patil