Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C programs with Visual Studio 2005?

Can I use Visual Studio 2005 to compile simple C programs? There appears to be only options to create projects for VB, C# or C++. If this is possible, what do I need to do?

like image 582
DaveDev Avatar asked Feb 05 '11 22:02

DaveDev


People also ask

Can you compile C in Visual Studio?

The Visual Studio build tools include a C compiler that you can use to create everything from basic console programs to full Windows Desktop applications, mobile apps, and more.

How do I use compile C code in Visual Studio?

After stopping the C file, go & click the File button at the top left corner of the Visual Studio Code Editor, and select the Settings via Preferences, as shown below image. After clicking the Settings, it shows the image below. In this image, select the extension button to set the settings for the C Compiler.

Does Visual Studio Code have C compiler?

VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.


3 Answers

To give you a more concrete answer, Visual Studio will definitely compile C code under a C++ project. It will even compile it as C code, not C++ - Visual Studio treats anything with a .c extension as C code and will compile as such by default. This is confirmed in the documentation on MSDN (albeit only specified for VS2008 and VS2010). There is even a compiler command line switch (/Tc) and an option in the properties page of any .c file to compile it as C++ code, rather than the C default.

like image 98
dlanod Avatar answered Sep 19 '22 06:09

dlanod


In general, C is a subset of C++. For a simple C program, just call it a C++ project. I don't have a copy of the software handy, but the odds are if you create a file with the '.c' extension, it'll be treated as C. [I should possibly have added: "... as it did in the versions of Visual Studio and Visual C++ that I've used since the early '90s.]

Update: for @R, who isn't as up to date on his programming languages as he thinks:

C++ is a direct descendant of C that retains almost all of C as a subset. C++ provides stronger type checking than C and directly supports a wider range of programming styles than C. C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency). In the same sense, ANSI C is a better C than K&R C. In addition, C++ supports data abstraction, object-oriented programming, and generic programming (see The C++ Programming Language (3rd Edition)"; Appendix B discussing compatibility issues is available for downloading). [Emphasis mine.]

The author of that statement is a fellow with some understanding of C++, by the name of Bjarne. And before you try to save yourself by pickily noting the "almost all of", read what I wrote: "In general, C..."

like image 37
Charlie Martin Avatar answered Sep 18 '22 06:09

Charlie Martin


My try to give graphical feedback on question. The screen shots taken from the properties dialog of a project (1PassCompilerFixNotation) and a source file (emitter.c) in Visual Studio 2008, should be identical with VS 2005.

For The Whole Project:

Right click on the projects node in Solution Explorer and select "Properties"

By setting the entry "Compile As" in the "Advanced" tab, syntax and semantic can be changed between

  • Compile as C Code (/TC)
  • Compile as C++ Code (/TP)

for the project. (See image below)

enter image description here

For A Specific File:

Right click on a C/C++ file in Solution Explorer and select "Properties"

By setting the entry "Compile As" in the "Advanced" tab, syntax and semantic can be changed between

  • Compile as C Code (/TC)
  • Compile as C++ Code (/TP)

for a specific file. (See image below)

Note: Specific file settings superseeds project default settings.

Compilersettings in Visual-Studio 2008

like image 41
LikeYou Avatar answered Sep 22 '22 06:09

LikeYou