-
October 10th, 2024, 01:52 AM
#1
Identifying the compiler language
I'm not talking about compilers, like MSVC or Clang etc - but within Visual Studio I can select C++14 or 17 or 20 etc. But C++14 offered features which got abandoned later (such as std::auto_ptr) and of course the later versions offer new features which weren't in C++14. So is there some way I can identify the language at compile time? Something like...
Code:
#if (I_SELECTED_C++17_OR_HIGHER)
// Build a small code section using the newer features
#else
// Carry on building it the old way
#endif
}
Last edited by John E; October 10th, 2024 at 02:04 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 10th, 2024, 03:55 AM
#2
Re: Identifying the compiler language
At compile time you can ascertain the version of the compiler being used with _MSC_VER or _MSC_FULL_VER See:
https://learn.microsoft.com/en-us/cp...?view=msvc-170
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)
-
October 10th, 2024, 06:35 AM
#3
Re: Identifying the compiler language
Sorry if I've misunderstood that page but it's not the compiler version I need - e.g. VS2013 as opposed to VS2019. What I'm looking for is which language version I've selected - e.g C++14 as opposed to C++17.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 10th, 2024, 07:54 AM
#4
Re: Identifying the compiler language
There is the __cplusplus macro. See:
https://learn.microsoft.com/en-us/cp...?view=msvc-170
Also have a look at vcruntime.h at around lines 275 - 300 for how MS tests for different C++ versions in the standard library.
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)
-
October 10th, 2024, 08:48 AM
#5
Re: Identifying the compiler language
Thanks... it looks like _MSVC_LANG might be what I need, though its name suggests it mightn't work if I'm using the Clang compiler option I'll try an experiment here...
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 10th, 2024, 09:10 AM
#6
Re: Identifying the compiler language
Woohoo! _MSVC_LANG seems to work for both MSVC and Clang. Many thanks, 2kaud
BTW - CodeGuru seems to have gone back to not sending email notifications when someone replies to a thread. I thought that got fixed months ago
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
October 10th, 2024, 09:40 AM
#7
Re: Identifying the compiler language
Originally Posted by John E
Woohoo! _MSVC_LANG seems to work for both MSVC and Clang. Many thanks, 2kaud
... I thought that got fixed months ago
Yes, that got fixed for a very short period. But then ...
However, private notifications do work as they do for many decades.
Victor Nijegorodov
-
October 10th, 2024, 10:00 AM
#8
Re: Identifying the compiler language
The list of MS supported macros is at:
https://learn.microsoft.com/en-us/cp...?view=msvc-170
However as _MSVC_LANG isn't standard there's no guarantee it'll work with another compiler (excluding clang under VS as that's still really VS). __cplusplus is standard across compilers.
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)
-
October 10th, 2024, 11:49 AM
#9
Re: Identifying the compiler language
@VictorN - there's something unsettling somehow about a forum for coders where they can't find a programmer to fix their own site's bugs
"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
|