dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] inline vs __inline

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,481

    [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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,195

    Re: inline vs __inline

    Victor Nijegorodov

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,481

    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

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,195

    Re: inline vs __inline

    Exactly!
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2017
    Posts
    325

    Re: inline vs __inline

    Quote Originally Posted by John E View Post
    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.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,362

    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++17 Compiler: Microsoft VS2017 (15.8.1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)