17

I am new to Visual Studio Environment and I am using VS2017 Pro. I wanted to write simple program in C and compiled with both c99 and c11 standards. In Visual Studio, I could only find compiler switches for C++ standards only.

How can we tell visual studio environment that we want to compile current code with c99 and c11 C standards.

Compiler Switch

Standard Switch

S.S. Anne
  • 14,415
  • 7
  • 35
  • 68
  • 10
    As far as I know, Visual Studio's C compiler doesn't fully support C99 or C11, so the question seems moot. – Retired Ninja Feb 26 '18 at 05:19
  • @RetiredNinja oh :( ... by the way thank you for the quick respond.. so then MSVC compiled with latest `C` standard by default? –  Feb 26 '18 at 05:24
  • 2
    For many purposes, MSVC only compiles with C90. However, the version you're using has considerably better support for C99 than older versions of MSVC — but as I understand it, that support is still not complete. – Jonathan Leffler Feb 26 '18 at 05:32
  • @JonathanLeffler Thank you for the info, I am thinking, Why didn't they provide at least an option for `C` standard switch :| –  Feb 26 '18 at 05:34
  • 4
    You would have to ask Microsoft, but the impression I have is that they're not interested in tracking C standards, just C++ standards. When there's a C++ feature that is also in a newer than C90 standard, they often add it to the C compiler mode as well at some point. – Michael Burr Feb 26 '18 at 05:36
  • @MichaelBurr got the point thank you. –  Feb 26 '18 at 05:41
  • 1
    Can somebody make an answer? I think the question quite interesting and the comments together make a good answer. Also I like to get practically answered questions out of the list of unsanswered questions. – Yunnosch Feb 26 '18 at 06:22
  • 2
    MSVC just [recently started supporting parts of c99](https://stackoverflow.com/a/27827416/1708801) and I have not heard about any support for C11. In general they support the latest they support with no way to specify a previous version of the standard. I believe they only recently allowed this for C++ due to breaking changes. – Shafik Yaghmour Feb 26 '18 at 07:00

2 Answers2

15

The only 'modes' supported by Visual C++ are: /std:c++14 mode for C++14 conformance (the default), /std:c++17 mode for C++17 support which is not quite complete as of VS 2017 (15.6). There is also a /std:c++latest mode which at some future point will include things in C++20. All of these should be combined with /permissive- for improved conformance.

To meet C++11 Standard Library conformance, Visual C++ has to support the C99 Standard Library, that's not the same thing as supporting C99 language conformance.

At some point to meet C++17 Standard Library requirements, Visual C++ will have to support the C11 Standard Library and again that's not the same thing as C11 language conformance.

See C++ Standards Conformance from Microsoft and C++11/14 STL Features, Fixes, And Breaking Changes In VS 2013

There is a comment thread in the post MSVC: The best choice for Windows where a Visual C++ project manager takes on the question of true 'C11' conformance.

Hi Onur,

C conformance is on our radar though we’re focusing on C++ conformance first.
We did some work in VS 2013 on C conformance, though we didn’t publicize it a lot. That work included:
– C99 _Bool
– C99 compound literals
– C99 designated initializers
– C99 variable declarations
We’re nearing the end of our C++ conformance work. One of the last items is a conforming preprocessor: a feature shared by C and C++. The preprocessor will mark the beginning of our C conformance push as well as the end of our C++98/11/14 conformance work.

Andrew

UPDATE: VS 2019 (16.8) will include /std:c11 and /std:c17 standards switches. See this blog post. Because the MSVC compiler does not support Variable-length Arrays (VLA) it does not claim C99 conformance. Note that these switches enable the new C99 preprocessor covered in this blog post.

Chuck Walbourn
  • 33,359
  • 2
  • 51
  • 77
11

Visual Studio is mostly a C++ compiler. In "C mode", it follows an ancient C standard from 1990.

Around 2013-2015, they made some effort to support not the current, but the previous C standard from 1999 ("C99"), some 16 years after its release. However, the work to conform to this standard has not been completed.

I believe the compiler also supports a few selected features of the current C language ("C11") such as the optional bounds-checking library. This standard has been available for 7 years but is not fully supported.

So if you need a conforming C language compiler, you should look for other alternatives.

Lundin
  • 174,148
  • 38
  • 234
  • 367
  • 1
    One reason why one might need a C compiler might be when programming against the Microsoft Windows API, which is written in C. So if you intend to do Windows programming, I would advise to pick a different compiler. – Lundin Feb 28 '18 at 11:54
  • Ludin thank you for the information, Which C compiler you prefer? `Intel C` compiler, `GCC` or `Clang` on Windows 10 and Ubuntu/Raspbian? –  Mar 01 '18 at 10:08
  • @Dinithi GCC/Mingw and occasionally Embarcadero (which, like VS, is mostly a C++ compiler). I haven't used the others much. – Lundin Mar 01 '18 at 10:16
  • I recently tried Embarcadero (Borland) C/ C++, kind of old school. :) I will go with GCC. –  Mar 01 '18 at 10:23
  • 5
    you can absolutely use the Windows API from C++. The headers all have `extern "C"` in them. – kibibu Oct 18 '18 at 23:01