Which C++ does Visual Studio 2008 (or later) use? - c++

I find C++ is very controversial language in microsoft world. By default we have ISO C++ and then microsoft has Managed C++ and now C++ CLI.
I just know standard (ISO) C++. I don't know microsoft's version of C++.
I'm confused about interpretation of any c++ code by visual studio 2008 (or later). Thats why I'm using gnu tools for compiling my programs. But I do love Visual Studio.
What settings do I need to make if I only want to use
STRICTLY ISO C++
Managed C++ (its deprecated but I think they still support it for sake of backward compatibility)
C++ CLI (for .NET platform)
I want to build native assemblies using C++ not managed ones. So, is there anything else should I need to do?

Everything is in the build settings:
Common Language Runtime Support (/clr) - add or remove CLR support
Advance Compile as C++ Code (/TP) - to choose if c++ or c..
Language: Disable Language Extention - use this to force ANSI.

When you ask Visual Studio to make a C++ project, it makes a C++ project. C++/CLI is a different language.
VS2008 and earlier have implemented C++03 (or approximated it. Like almost every other compiler, there are bits of the standard that are not followed to the letter. A few features are not implemented (exception specifications, the export keyword or two-phase name lookup are the ones I can think of), and some proprietary extensions are added as well.
GCC, and most big compilers, do the exact same thing, so this isn't a case of Microsoft being "evil" as such. The extensions can be disabled, leaving you with a reasonably standards-compliant compiler.
VC2010 is adding a number of C++0x features (and at least in the beta, I haven't been able to find an option to disable these), so from a strict C++03 compliance point of view, it is going to be less compliant.
Dani's answer already tells you which settings to change to enable/disable different language dialects.

Related

Visual Studio 2019 - force C++11 features only

I use Visual Studio 2019 for C++ development. Due to constraints of legacy systems that code will be deployed to, I am limited to using only C++11 language features (specifically GCC 4.8.5).
The default in VS2019 is C++14, which is obviously a super set of C++11. I can't see a way to specify C++11 only. This would be useful as a much faster way to see if I accidentally include newer C++ features than seeing things fail in the build system.
Is there any way to change this setting?
I am afraid it's not possible.
there is no plan to add a C++11 switch
Link: Standards version switches in the compiler
The compiler doesn't support standards options for C++98, C++03, or
C++11.
/Zc:__cplusplus

The C++ standard versions vs Visual Studio versions

The /std (Specify Language Standard Version) option is available in Visual Studio 2017 and later. Does it mean that previous versions of Visual Studio use particular versions of the C++ standard and, unlike gcc/clang, there's a 1:1 mapping between a VS version and the default C++ standard version provided by the compiler?
There is a blog post Standards version switches in the compiler that explains the introduction of the feature and what MSVC used to do previously:
Traditionally, we would release the compiler in a default mode that combines features striding several versions of the C++ language, e.g. C++98, C++03, C++11, C++14, etc. in addition to conformance improvement bug fixes. This can lead to situations where it is difficult to simultaneously upgrade to the newer and better compiler and at the same time move your code forward. We really appreciate the great feedback you’ve given us about our conformance improvements and new feature work. As the C++ standards committee is gearing up for a new C++ version, we’ve taken the initiative to help you state in your build systems or compiler command lines which version of C++ you are comfortable with while updating to the next version of Visual C++.
Visual C++ has made significant progress towards C++ standards conformance between the first release of Visual Studio 2015 and VS 2015 Update 3. We’ve fixed many issues with constexpr, improved expression SFINAE support, evaluation of initializer lists, variable templates, and more. Our standard library implementation has kept pace with features adopted into the post-C++14 standard draft. And we’ve implemented some major features currently under consideration by the committee, including C++ modules and coroutines. We want you to benefit from all this, but also we want you to consume these features at your own pace, while upgrading to this new update.
All post-C++14 features implemented in this update are off by default; those which were included in previous releases are left on to avoid causing your builds.
...
From what I gather /std:c++17 would be equivalent to clang/gcc -std=c++17 argument.
Some versions of msvc may not fully implement some versions of iso C++.
Depending on the Visual C++ compiler version or update level, certain C++14 or C++17 features may not be fully implemented or fully conformant when you specify the /std:c++14 or /std:c++17 options. For example, the Visual C++ 2017 RTM compiler does not fully support C++14-conformant constexpr, expression SFINAE, or 2-phase name lookup.
(cf: https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2017 )
So that's not exactly a "1:1 mapping between VS version and the default C++ standard version provided by the compiler".
You shouldn't rely on that.
Instead you should read the docs for the version of VS you're using.
Hope this answers your question.

Writing C++ code for Linux platform in Visual studio

I am writing code in VS that should be ported later to Linux. I found that sometimes, I may use some functions or code that is available only on Windows and not on Linux.
Is there any way that I can set my Visual Studio to report me these non portable pieces of code?
I prefer to use VS during development and then use the code base and compile it in Linux.
You can treat MinGW as a reference compiler, just to check whether the code you write is portable.
You can also disable MSVC compiler extensions in the compiler options settings in Project Properties (or set /Za flag). That will most likely make at least <windows.h> stop compiling.
Frankly, though, I don't see a problem in simply not using nonportable things. Stick to standard library and libraries that you know are portable and you're good to go. (granted, syntactic extensions are easier to accidentally use, but then again their usages are also typically trivial to put back in proper way).

visual c++ and C++ builder

Can C++builder compile any c++ source files.
I don't have a good knowledge in c++. but i have some experience in delphi.
I like to use c++ but confused which one to use
I know that cbuilder has vcl , easy to develop ,easy for delphi developer
But my problem is can it compile any c++ files (vc++ and other source files).
is it compatible with vc++ (excluding MFC and VCL). Can i use any APIs with c++builder
You'll find C++ Builder very comfy coming from Delphi if you don't care about MFC or .NET via C++/CLI etc and just want native C++ then either will work for you. Visual Studio 2010 supports a lot of the new C++0x features which is pretty nice, although they don't have variadic templates yet. I'm not sure how much of C++0x is in C++ Builder as yet but that could be worth looking into as a deciding factor.
It should be able to compile any standards conforming code. If the code uses extensions that another compiler provides, it will more than likely have problems. VC++ has quite a few extensions that are on by default and so someone using that compiler might use them with out realizing what is going on(the same applies to G++ the other major C++ compiler out there.)
In my experience, C++Builder's support for more advanced C++ code is limited. For example, many of Boost's libraries are unsupported in C++Builder, and I've often had to modify other open source libraries to get them to build properly in C++Builder (due to various bugs or limitations in C++Builder's compiler). Simpler C++ code can work without any problems.
So, depending on what C++ libraries / source files / APIs you're wanting to use, getting them to work in C++Builder may be very straightforward, or it may take significant work.
You can download a free version of C++ Builder at www.embarcadero.com. With that, you can test your libraries for compatibility.

Disabling C++0x features in VC 2010?

Does C++0x mode in VC++ 2010 has an off switch? I am working on a project that supposed to compile on non 0x compilers, and therefore I want to compile against the current standard. (Even if non of the new features are being used directly, there are still subtleties that makes C++0x more premissive).
The closest switch I found was Configuration Properties -> C/C++ -> Language -> Disable Language Extensions but that's not it.
No, language extensions are typically non-standard vendor specific additions.
C++0X features: There is no direct way to switch off these features. One workaround is to not use them. However, note that there will still be marked difference in performance across versions of VC runtime. VC10 implements move semantics and the standard library (std::string for example) uses these features generously.
A reasonable compromise in my opinion is to switch back to VS2008. Recent VS versions have been notoriously buggy (so far, in my experience) and have never worked the way they should without a Service Pack. VS2008 is pretty stable now, without any of those C++0x features and ought to fit your bill.
It appears you can use the vc2008 toolset in VS2010 see: Visual C++ 2010 compatibility with VC 2008