David Vandevoorde a écrit :> > I don't think those are _good_ reasons though: If one doesn't want a C+ > + function to be inlined, one shouldn't define it inline. > >You must not have written a lot of C++ template then. You don't have the choice in this case, just check your STL header.> > FWIW, I've been involved in a couple of attempts by commercial > compilers to relegate "inline" to the same status as "register" -- an > obsolete hint ignored by the compiler -- and so far that always proved > to be unpractical because some critical calls that were previously > inlined were no longer being inlined after the change. (That's just > annecdotal, of course: LLVM may have gotten good enough to make it > practical. If that's the case, I still think it's too early to write C > ++ code with that assumption.) >There is often a keyword force_inline or alwais_inline if needed Cédric
Cédric Venet <cedric.venet at laposte.net> writes:> David Vandevoorde a écrit : >> >> I don't think those are _good_ reasons though: If one doesn't want a C+ >> + function to be inlined, one shouldn't define it inline. > > You must not have written a lot of C++ template then. You don't have the > choice in this case, just check your STL header.LOL! -- Óscar
On Aug 27, 2009, at 3:07 AM, Cédric Venet wrote:> David Vandevoorde a écrit : >> >> I don't think those are _good_ reasons though: If one doesn't want >> a C+ + function to be inlined, one shouldn't define it inline. >> >> > > You must not have written a lot of C++ template then.(Ha!)> You don't have the choice in this case, just check your STL header.I don't think that how standard library or STL headers _are_ written determines how they _should be_ written. (Templates don't force us to write excessive inline functions: Leave off the inline keyword and write a member function outside the class template definition, and it's no longer an inline function.)> >> >> FWIW, I've been involved in a couple of attempts by commercial >> compilers to relegate "inline" to the same status as "register" -- >> an obsolete hint ignored by the compiler -- and so far that always >> proved to be unpractical because some critical calls that were >> previously inlined were no longer being inlined after the change. >> (That's just annecdotal, of course: LLVM may have gotten good >> enough to make it practical. If that's the case, I still think >> it's too early to write C ++ code with that assumption.) >> > > There is often a keyword force_inline or alwais_inline if neededYes, but that's not portable. It's also not the same thing (and usually less useful than a plain "inline" hint, IMO). Daveed
David Vandevoorde a écrit :> On Aug 27, 2009, at 3:07 AM, Cédric Venet wrote: > > >> David Vandevoorde a écrit : >> >>> I don't think those are _good_ reasons though: If one doesn't want >>> a C+ + function to be inlined, one shouldn't define it inline. >>> >>> >>> >> You must not have written a lot of C++ template then. >> > > (Ha!) >:) ok, your name didn't register at first, but I have read (part of) your book. sorry for the tone of my reply which was not very friendly (It happen often to me with mail, but this is not an excuse). I just didn't and still don't understand how you do it, but this is probably not the good place to discuses this. please accept my sincere apologies.> > I don't think that how standard library or STL headers _are_ written > determines how they _should be_ written. > > (Templates don't force us to write excessive inline functions: Leave > off the inline keyword and write a member function outside the class > template definition, and it's no longer an inline function.) >What about multiple translation unit then? because from my understanding, this will generate multiple definition of symbol, so you will never be able to link it (except with some strange link specification (weak or something like this) which seem less portable than declaring the function inline). From the standard: Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined (see 12.1, 12.4 and 12.8). An inline function shall be defined in every translation unit in which it is used. regards, Cédric