-
May 17th, 2018, 12:02 AM
#1
[RESOLVED] inline vs __inline
Somebody's sent me some code where one of the header files contains a function looking like this:-
Code:
static inline int32_t the_function_name()
{
// the function body
}
I tried building this with MSVC-8 but it doesn't like inline - however, it's happy if I precede it with a couple of underscores:-
Code:
static __inline int32_t the_function_name()
{
// the function body
}
What's interesting is that in both cases, inline and __inline get printed in blue (i.e. the compiler recognises them as keywords) but it must interpret them to mean something different. I just wondered if anyone knows what the difference is?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
May 17th, 2018, 02:12 AM
#2
Re: inline vs __inline
Victor Nijegorodov
-
May 17th, 2018, 02:44 AM
#3
Re: inline vs __inline
A great link Victor, thanks. Here's what I learned...
The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++.
I think that explains it !!
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
May 17th, 2018, 03:30 AM
#4
Re: inline vs __inline
Exactly!
Victor Nijegorodov
-
May 19th, 2018, 01:52 AM
#5
Re: inline vs __inline
Originally Posted by John E
A great link Victor, thanks. Here's what I learned...
"The inline keyword is available only in C++."
That's not quite true, inline has been part of C since version C99 (which is the C version that C++ 11 builds on).
But inline in C and C++ differ slightly and I suppose the Microsoft specific __inline keyword has been introduced to equalize this difference to some common inlining functionality that Microsoft finds useful in a mixed C/C++ situation.
So inline is defined by the C and C++ standards whereas __inline is vendor specific (in this case Microsoft) and defined by that vendor. Personally I think one should stick to the standards even when it means a little more effort.
Last edited by wolle; May 19th, 2018 at 04:01 AM.
-
May 19th, 2018, 04:31 AM
#6
Re: [RESOLVED] inline vs __inline
As the link in Victor's post #2 says,
The inline keyword is available only in C++.
If you are using MS VS to compile c programs (as opposed to c++), note that their c compiler doesn't implement all of the c standard (since c99)- and is not likely to as MS sees their VS as c++ with c being very much a poorer relation. If you need a c total compliant compiler then you'll need to look elsewhere.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|