Topic: forceinline" useful new keyword for inline substitution?
Author: "Daniel M. Pfeffer" <pfefferd@nospam.internet-zahav.net>
Date: 1999/10/28 Raw View
IMHO, this is a compiler technology issue. At one time, it was essential for
C program writers to specify register variables if they wanted the extra
speed. Today, the static analysis capabilities of compilers have improved to
the extent that it is often difficult to improve on the compiler's
enregistering choices. I suspect that similar improvements will occur in C++
technology, given time.
--
Daniel Pfeffer
--------------
Remove 'nospam' from my address in order to contact me directly
Niels Dekker <ndekker@NO_SPAM_PLEASEnki.nl> wrote in message
news:381365C0.146F265D@NO_SPAM_PLEASEnki.nl...
> One of my classes has an inline declaration like this:
> template<unsigned uCount> struct MyIterator
> {
> inline bool GoToNext(void);
> // ...
> };
>
> To me it is really important that GoToNext is as fast as possible, so I
declared it
> "inline".
> But what does the inline declaration mean? It tells the compiler that the
definition
> of the function is in every translation unit that uses it. And it suggests
the
> compiler to use inline substitution.
> But the compiler is free to ignore this suggestion. And for this
particular function
> I want to be sure that it is substituted inline, for every call!
>
> MSVC++ 5.0 and 6.0 (both with 3 "service packs") refuse to inline-expand
calls to my
> GoToNext function in some cases. (Especially when GoToNext is called
within a
> template function.)
> The compilers tell me so when I do a release compilation with all warnings
enables.
>
> Now in MSVC++ 6.0 there is a new keyword, "__forceinline". This solves my
problem.
> But I'd rather stick to Standard C++!
>
> Are there plans to include a keyword like "forceinline" to the Standard?
>
> For the time being I use a macro as workaround:
> #if ( defined(_MSC_VER) && (_MSC_VER == 1200) &&
defined(_MSC_EXTENSIONS) )
> #define FORCE_INLINE __forceinline // For MSVC++ 6.0
> #else
> #define FORCE_INLINE inline // For all other compilers.
> #endif
>
> Can I use this macro for a member function definition that is inside a
class
> definition?
> I mean, is it allowed in Standard C++ to add an "inline" keyword to a
member
> function that is defined inside a class? (Okay, it is is overdone, but is
it
> correct?)
>
> Do other compilers have a simular "extension" to Standard C++ to allow the
> programmer to enforce inlining?
>
> For the "__forceinline" keyword of MSVC++ 6.0 see:
>
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_langref_inlin
e.2c_.__inline.htm
>
> Regards from Amsterdam,
>
> Niels Dekker
> ndekker at nki.nl
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Ken Hagan" <K.Hagan@thermoteknix.co.uk>
Date: 1999/10/25 Raw View
Niels Dekker wrote in message <381365C0.146F265D@NO_SPAM_PLEASEnki.nl>...
>Now in MSVC++ 6.0 there is a new keyword, "__forceinline". This solves my
problem.
>But I'd rather stick to Standard C++!
>
>Are there plans to include a keyword like "forceinline" to the Standard?
Difficult to see how "forceinline" could handle recursive functions, or
mutually recursive groups of functions, so it would either have to be
"advisory" or someone would have to carefully enumerate all the cases
which "had to work" (having convinced the committee's compiler vendors
that this wasn't an unacceptable imposition on them!).
MS list several other cases where forceinline has to be ignored, and
already offer 2 pragmas which relate to inlining, so I'm surprised they
even bothered to add this feature. I've never considered using it, but then
I'm not writing your program. I think you've found a rare case where
__forceinline makes a difference and is the only way to make that
difference. Perhaps MS added it because they were aware that the
built-in judgement wasn't good enough, but that's no reason to ask others
to follow suit.
As far as standardising is concerned, I think you'd have to convince people
that *few* compilers are *likely* to inline your function, but *most*
compilers
*could*, and that some clear benefit may be gained from forcing the issue.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: comeau@panix.com (Greg Comeau)
Date: 1999/10/25 Raw View
In article <381365C0.146F265D@NO_SPAM_PLEASEnki.nl> Niels Dekker <ndekker@NO_SPAM_PLEASEnki.nl> writes:
>MSVC++ 6.0 there is a new keyword, "__forceinline". This solves my problem.
>But I'd rather stick to Standard C++!
>
>Are there plans to include a keyword like "forceinline" to the Standard?
Not that I know of. If anything, some folks (in the community, not
particularly the committee) probably would like to remove the inline keyword.
And of course, this begs for a "donteverinline" and probably some others.
>For the time being I use a macro as workaround:
>#if ( defined(_MSC_VER) && (_MSC_VER == 1200) && defined(_MSC_EXTENSIONS) )
>#define FORCE_INLINE __forceinline // For MSVC++ 6.0
>#else
>#define FORCE_INLINE inline // For all other compilers.
>#endif
>
>Can I use this macro for a member function definition that is inside a class
>definition?
>I mean, is it allowed in Standard C++ to add an "inline" keyword to a member
>function that is defined inside a class? (Okay, it is is overdone, but is it
>correct?)
Seems to be. FORECE_INLINE will be replaced before the compiler proper
so to speak gets it, so it should be no problem.
Too, you may want to see if the compiler supports a #pragma.
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C/C++ 4.2.38 -- NOTE 4.2.42 BETAS NOW AVAILABLE
Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
*** WEB: http://www.comeaucomputing.com ***
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: dennis51@my-deja.com
Date: 1999/10/27 Raw View
In article <381365C0.146F265D@NO_SPAM_PLEASEnki.nl>,
Niels Dekker <ndekker@NO_SPAM_PLEASEnki.nl> wrote:
> One of my classes has an inline declaration like this:
> template<unsigned uCount> struct MyIterator
> {
> inline bool GoToNext(void);
> // ...
> };
>
> To me it is really important that GoToNext is as fast as possible, so
I declared it
> "inline".
> But what does the inline declaration mean? It tells the compiler that
the definition
> of the function is in every translation unit that uses it. And it
suggests the
> compiler to use inline substitution.
> But the compiler is free to ignore this suggestion. And for this
particular function
> I want to be sure that it is substituted inline, for every call!
>
> MSVC++ 5.0 and 6.0 (both with 3 "service packs") refuse to
inline-expand calls to my
> GoToNext function in some cases. (Especially when GoToNext is called
within a
> template function.)
> The compilers tell me so when I do a release compilation with all
warnings enables.
I see that you only declare the function there.
If you replace that declaration with the definition
including the body of the function, will the compilers
still refuse to inline it sometimes?
How big is this function, anyway?
Can you post it for us to see?
Dennis Yelle
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Niels Dekker <ndekker@NO_SPAM_PLEASEnki.nl>
Date: 1999/10/25 Raw View
One of my classes has an inline declaration like this:
template<unsigned uCount> struct MyIterator
{
inline bool GoToNext(void);
// ...
};
To me it is really important that GoToNext is as fast as possible, so I declared it
"inline".
But what does the inline declaration mean? It tells the compiler that the definition
of the function is in every translation unit that uses it. And it suggests the
compiler to use inline substitution.
But the compiler is free to ignore this suggestion. And for this particular function
I want to be sure that it is substituted inline, for every call!
MSVC++ 5.0 and 6.0 (both with 3 "service packs") refuse to inline-expand calls to my
GoToNext function in some cases. (Especially when GoToNext is called within a
template function.)
The compilers tell me so when I do a release compilation with all warnings enables.
Now in MSVC++ 6.0 there is a new keyword, "__forceinline". This solves my problem.
But I'd rather stick to Standard C++!
Are there plans to include a keyword like "forceinline" to the Standard?
For the time being I use a macro as workaround:
#if ( defined(_MSC_VER) && (_MSC_VER == 1200) && defined(_MSC_EXTENSIONS) )
#define FORCE_INLINE __forceinline // For MSVC++ 6.0
#else
#define FORCE_INLINE inline // For all other compilers.
#endif
Can I use this macro for a member function definition that is inside a class
definition?
I mean, is it allowed in Standard C++ to add an "inline" keyword to a member
function that is defined inside a class? (Okay, it is is overdone, but is it
correct?)
Do other compilers have a simular "extension" to Standard C++ to allow the
programmer to enforce inlining?
For the "__forceinline" keyword of MSVC++ 6.0 see:
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_langref_inline.2c_.__inline.htm
Regards from Amsterdam,
Niels Dekker
ndekker at nki.nl
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]