Mr. Compiler, would you please inline this function?

I’ve always read that marking a function inline doesn’t guarantee that the compiler will actually inline it, but it’s merely a hint to the compiler to “try its best” to do it. Which have always raised the question in my head, how do I know if Mr. Compiler agreed to inline my function? Do I have to look at the generated assembly code? There has to be an easier way!

So I invested 15 minutes researching that issue and found out that Mr. Compiler is friendly enough to let you know if it was not possible to fulfill your request to inline a certain function by issuing a warning.

For Microsoft’s VC8 compiler warning C4710 is turned off by default, you can turn it on by doing any of the following (depends on your choice):

  1. #pragma warning (default : 4710)
  2. #pragma warning (custom_warning_level : 4710)

For GCC the -Winline switch can be used to achieve the same thing.


Post a Comment

Required fields are marked *

*
*