-
May 3rd, 2021, 02:21 AM
#1
__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
-
May 3rd, 2021, 04:05 AM
#2
Re: __cplusplus number
Victor Nijegorodov
-
May 3rd, 2021, 04:14 AM
#3
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
-
May 3rd, 2021, 04:32 AM
#4
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)
-
May 3rd, 2021, 05:41 AM
#5
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
-
May 3rd, 2021, 05:50 AM
#6
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)
-
May 3rd, 2021, 09:02 AM
#7
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
-
May 4th, 2021, 03:05 AM
#8
Re: __cplusplus number
Originally Posted by John E
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
-
May 4th, 2021, 03:15 AM
#9
Re: __cplusplus number
Do you mean something like this?
Victor Nijegorodov
-
May 4th, 2021, 08:01 AM
#10
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
-
May 4th, 2021, 08:13 AM
#11
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)
-
May 4th, 2021, 08:20 AM
#12
Re: __cplusplus number
Originally Posted by John E
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
-
May 4th, 2021, 09:01 AM
#13
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
-
May 4th, 2021, 09:32 AM
#14
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.
-
May 4th, 2021, 11:22 AM
#15
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
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
|