This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Understanging the use of inline funtions


John Fine <johnsfine@verizon.net> writes:

>> 1. The inline keyword is just a hint. The compiler decides if it uses
>> it or not.
>>   
> True.  Compared to other C++ compilers, GCC gives the programmer more
> control over whether things are inlined, including more often simply
> obeying the inline keyword.  But in the language standard the inline
> keyword is just a hint.  Whether GCC obeys that hint depends on a
> variety of switches and other factors.

In C the inline keyword is just a hint.  However, in C++, the inline
keyword gives a function internal linkage.  If you write
    void fn() { }
in a .cc or .h file, and there are no calls to fn, then the object file
will contain a definition of the function fn.  If you write
    inline void fn() { }
then it will not contain a definition if there are no calls.

In other words, in C++ the inline keyword has a language meaning which
changes the linkage of the function.  That said, with regard to whether
the compiler actually inlines a function rather than emitting it out of
line, the inline keyword is just a hint.


>> 4. GCC does inlining not below -O3 or the explizit activation using
>> -finline-functions
>>   
> I'm not sure.  I think the decision rules are more complex and depend
> on more switches and there would be exceptions to a statement as
> simple as the above.

Yes.  For example, -finline-functions-called-once is on by default at
all optimization levels.  The algorithm which chooses which functions to
inline is complex, and can be controlled by -finline-limit and by
various tuning parameters.


>> And that also means to me, that there is no way to _not_ inline code if
>> it is given in the header file,
> Using the Intel 10 compiler at a decent level of optimization, it is a
> constant source of frustration that there is no way to tell it to not
> inline things defined in header files.  The project I work on has some
> very large templates that must be in header files and shouldn't be
> inlined.  The Intel 10 compiler always uses its own judgment and its
> own judgment is usually wrong.
>
> I don't use GCC much in similar situations, but I don't think GCC is
> that flawed on this issue.  I think there are practical ways to get it
> to not inline such functions.

Such as __attribute__ ((noinline)).  The Intel compiler recognizes a lot
of gcc attributes and may recognize that one.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]