c++inline-functions

Is there a way to ensure that functions get inlined?


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?


Solution

  • 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.