Re: about inline functions
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Thu, 30 Apr 2009 03:21:17 GMT
CBFalconer wrote:
Christian Kandeler wrote:....s0suk3@xxxxxxxxx wrote:
But inline avoids a problem when you want to have a header fileBut you can achieve roughly the same effect by declaring the function static.
that contains an inline function, and that header is included
in more than one file.
'static' for a function has nothing to do with inline. It simply
means that the functions is not accessible from outside the source
file in which it is declared, except when specifically passed out
as a pointer to a function.
Yes and no. 'inline' is just a hint to the compiler. The point is, a static function provides very nearly the same hint.
A static function, often doesn't have to be an actual function - it could be in-lined at each call, and a good optimizing compiler will do just that, taking advantage of the as-if rule. Some features of the code can prevent inlining it, such as taking a pointer to the function, especially if that pointer is passed to code in some other translation unit. However, if you have a function for which 'inline' is a good idea, it's often the case that simply declaring it 'static' without the 'inline' keyword is sufficient to allow the compiler to perform this optimization.
It was for this reason that many people opposed the creation of the 'inline' keyword. Using 'static' doesn't guarantee that the function will be inlined, even if there's no good reason not to - but the same can be said of the 'inline' keyword.
.
- Follow-Ups:
- Re: about inline functions
- From: Chetan
- Re: about inline functions
- From: Han from China
- Re: about inline functions
- References:
- about inline functions
- From: \"\"
- Re: about inline functions
- From: Falcon Kirtaran
- Re: about inline functions
- From: Malcolm McLean
- Re: about inline functions
- From: s0suk3
- Re: about inline functions
- From: CBFalconer
- about inline functions
- Prev by Date: Re: C program
- Next by Date: Re: The 64bit future
- Previous by thread: Re: about inline functions
- Next by thread: Re: about inline functions
- Index(es):
Relevant Pages
|