This is the mail archive of the gcc@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: -fobey-inline (was Re: gcc and inlining)


On Tuesday, 18 March 2003 05:31, Joe Buck wrote:
> On Sun, Mar 16, 2003 at 03:41:17PM -0300, Alexandre Oliva wrote:
> > On Mar 15, 2003, Bernd Schmidt <bernds at redhat dot com> wrote:
> > > And why not?  If I add the "inline" keyword, I do it for a good
> > > reason (I want the function inlined).
> >
> > What if you don't add the `inline' keyword, but define a member
> > function inside the class body in C++?  Per the C++ Standard, such
> > a member function is implicitly `inline'.  Must this inline marker
> > get the same weight as a function defined outside the class body,
> > with the inline keyword explicitly given?
>
> I would be willing to accept as a compromise that such implicit
> inline requests are somehow "weaker" than explicit use of the inline
> keyword. But it's frustrating to have to write nonstandard C++
> (sorry, use of GNU directives is nonstandard) to get the compiler to
> behave as requested when the word "inline" is explicitly typed.

The vast majority of inline functions in modern C++ are templates. 
Templates _have_ to be inline, either defined inside a class definition 
or explicitly marked inline if they're defined out of line or aren't 
class members. There's no portable way to use templates without marking 
them inline.

That means most inline functions in C++ are that way because they have 
to be to make the syntax work, with no reason to suspect that they're 
more deserving of actual inlining than any other functions. Giving high 
weight to the inline tag is undoubtedly one of the reasons why GCC 
produces inferior code to smarter compilers like Intel's.

I'd like to see GCC simply ignore the inline tag in its inlining 
heuristics. This would certainly produce better code from C++ than the 
current system; the rare cases when the compiler isn't smart enough to 
inline something that should be inlined will be vastly outweighed by 
the enormous number of functions that shouldn't be inlined but have to 
be tagged inline because of a language misfeature.

Failing that, at least don't make the situation any worse than it 
already is. You C programmers can do what you like, but for C++, don't 
even think about giving inline any more weight than it has now; it 
already has far too much.

-- 
Ross Smith ......... r-smith at ihug dot co dot nz ......... Auckland, New Zealand

Eagles may soar, but weasels never get sucked into a land war in Asia.


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