CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    __cplusplus number

    I'm involved in a project written for gcc (although I build with VS2019). Recently, someone added a section like this:-

    Code:
    # if (defined(__cplusplus) &&  __cplusplus >= 201709L)
          // Some functionality
    # emdif
    Even in VS2019, Intellisense removes that code section - so I did some digging and realised that in Properties->General my C++ Language Standard was set to the default (ISO C++14 Standard). So I tried the various alternatives but nothing makes that section appear. Is there some other setting I need to change? I'm assuming that for VS2019 the value of __cplusplus should be higher than 201709

    [Edit...] FWIW if I add the line:- long my_test = __cplusplus; to some module, the returned value seems to be 199711
    Last edited by John E; May 3rd, 2021 at 03:55 AM.
    "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
    20,395

    Re: __cplusplus number

    Victor Nijegorodov

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

    Re: __cplusplus number

    Thanks Victor - so it looks like VS2019 is still only implementing the basic C++98
    "A problem well stated is a problem half solved.” - Charles F. Kettering

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

    Re: __cplusplus number

    You need to use the _Zc option. See https://docs.microsoft.com/en-us/cpp...?view=msvc-160

    Note that for at least C++17 its 201703L and not 201709L
    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)

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

    Re: __cplusplus number

    Thanks 2kaud - that does give me 201703 for __cplusplus but I see this error now when #including a particular header file from one of the (non-MSVC) support libs:-

    Code:
    >F:\GTK-SOURCES\gnu-windows\include\glibmm\objectbase.h(215,13): error C2039: 'auto_ptr': is not a member of 'std'
    So I'm guessing this must be something that's changed between C++98 and C++17
    "A problem well stated is a problem half solved.” - Charles F. Kettering

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

    Re: __cplusplus number

    auto_ptr was depreciated with C++11 and removed with C++17 as there were issues with it's implementation. Use either unique_ptr or shared_ptr as appropriate which are what replaced it.

    Any C++ code that still uses auto_ptr is outdated and should be replaced.
    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)

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

    Re: __cplusplus number

    BTW - I achieved this by adding /Zc:__cplusplus in Configuration Properties->C++->Command Line->Additional Options. And AFAICT that seems to be the only way to do it (which is needed for every single project...)

    I'm quite surprised there isn't some place globally that'd just enable this option or disable it for all builds.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

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

    Re: __cplusplus number

    Quote Originally Posted by John E View Post
    I'm quite surprised there isn't some place globally that'd just enable this option or disable it for all builds.
    An idea just occurred to me... what about the .props file? Most of my projects share a common properties file so could something get added there that would have the same effect as /Zc:__cplusplus
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: __cplusplus number

    Do you mean something like this?
    Victor Nijegorodov

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

    Re: __cplusplus number

    Thanks Victor - is MSBuild the same compiler that Visual Studio uses internally? I always thought it was a separate command-line utility. I remember that the VS linker is called clink.exe and the resource compiler's called rc.exe - but I can't quite remember what the main C++ compiler's called.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

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

    Re: __cplusplus number

    The c/c++ compiler/linker is cl.exe msbuild.exe is for the .net framework. clink.exe is no longer used.
    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)

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: __cplusplus number

    Quote Originally Posted by John E View Post
    Thanks Victor - is MSBuild the same compiler that Visual Studio uses internally? I always thought it was a separate command-line utility. I remember that the VS linker is called clink.exe and the resource compiler's called rc.exe - but I can't quite remember what the main C++ compiler's called.
    I don't know.
    See MSBuild (C++).
    Victor Nijegorodov

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

    Re: __cplusplus number

    So somehow... I'd need to be able to add command line arguments in a .props file - in the same way that I can add Include directories / Library directories etc. I don't know if that's possible but I'd be surprised if it isn't.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  14. #14
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: __cplusplus number

    An entry like this should work in a .props file:
    <ItemDefinitionGroup>
    <ClCompile>
    <AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
    </ClCompile>
    </ItemDefinitionGroup>

    Just look at your .vcxproj file where you can find a similar entry.

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

    Re: __cplusplus number

    Looks promising Richard - thanks! I've only tried a simple project to experiment with but it did seem to work... I'll try something a bit more complex tomorrow
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured