Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Ask experience of inline in C++?

Author: Jon Dart

Date: 06:59:32 05/08/01

Go up one level in this thread


>
>Now I am wondering that compiler may embed directly the expression of parameter
>from function B into A, it means instead of calling that expression one time and
>use its results 100 times, now I may waste time by calling it 100 times!!!

I'm not sure I fully understand, but I'll try to answer.

If the expression can be evaluated at compile time (for example, its terms are
constants and/or static defines) then most compilers will do this evaluation and
replace it with a single constant. If the expression can't be evaluated at
compile time (for example, it references a global variable that is set during
initialization) then the compiler will not pre-calculate and cache the value (at
least, I don't know of any compiler that will do this). However you could do
this optimization yourself.

Note also that A and B are only candidates for inlining. Whether you actually
get inlining of A into B, or B into its caller, depends on the complexity of the
code in these functions and possibly on the local context (e.g. which registers
are available). You can, however, force inlining in Visual C++ with the
vendor-specific keyword __forceinline.

--Jon





This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.