Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show errors when I write C++ code in C?

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?

like image 513
Berecz Balázs Avatar asked Mar 02 '23 17:03

Berecz Balázs


1 Answers

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:

enter image description here

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).

like image 159
Adrian Mole Avatar answered Mar 05 '23 06:03

Adrian Mole