Reputation: 153
I have to write my assignment in C but I don't want to download a new IDE just for this course. I want to use VS 2019 and MSVC to compile it, but I would like to generate errors for things that aren't in C. Is this possible?
Upvotes: 4
Views: 241
Reputation: 11
To write in C program in Visual Studio, create your project as if you were going to set up a C++ project, but name your source files with a .c extension. This will cause them to be compiled assuming C syntax, because files with .cpp extensions are assumed to be C++ source code.
Not every C99 feature is implemented in the C compiler. This is an issue if you only want to do some complex projects.
Upvotes: 0
Reputation: 51905
By default, MSVC will compile files with the .c
extension as "C" and files with the .cpp
extension as "C++". However, if (for whatever reason) this does not seem to be the case, you can specify which language to use on a project-basis (or even on an individual source file basis).
To do this, right-click on the project in the Solution Explorer and select the "Properties" command. In the displayed dialog box, open the C/C++
node and select the Advanced
item; then, choose "Compile as C Code" in the Compile As
property. Like this:
You can do the same for an individual file within a project by right-clicking on that file, rather than on its containing project.
NOTE: The plain "C" compiler native to Visual Studio (MSVC) uses a very old language standard. You may find the clang-cl plug-in very useful, as that complies to a more modern standard (it uses the LLVM compiler). You can install it via the "Visual Studio Installer" program (if you have VS-2019).
Upvotes: 7