开发者

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开发者_C百科 do?


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.


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)

Compile C programs with Visual Studio 2005?

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.

Compile C programs with Visual Studio 2005?


Microsoft Visual Studio 2005 comes with a solid C89/90 compiler. There are no issues using C in VS2005. Files with .c extension will be automatically compiled as C files. (Or you can override the language by using project settings/command line switches as described in other answers).

Just keep in mind, again, that VS compilers only support the "classic" C89/90. There's no support for C99 features (not even mentioning C11).


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


Select C++ console, and you should be fine. VS will tend to want to use .cpp /etc extensions, but you should be able to use.c and .h extensions,


Just use the c++ option. You can if you wish use .c extensions rather than .cpp, but plain old c will compile just fine in a c++ project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜