Question

When should I use __forceinline instead of inline?

Visual Studio includes support for __forceinline. The Microsoft Visual Studio 2005 documentation states:

The __forceinline keyword overrides the cost/benefit analysis and relies on the judgment of the programmer instead.

This raises the question: When is the compiler's cost/benefit analysis wrong? And, how am I supposed to know that it's wrong?

In what scenario is it assumed that I know better than my compiler on this issue?

 47  38451  47
1 Jan 1970

Solution

 72

You know better than the compiler only when your profiling data tells you so.

2008-09-30

Solution

 37

The one place I am using it is licence verification.

One important factor to protect against easy* cracking is to verify being licenced in multiple places rather than only one, and you don't want these places to be the same function call.


*) Please don't turn this in a discussion that everything can be cracked - I know. Also, this alone does not help much.

2008-10-26