开发者

Is it possible for Visual C++ 2008 Express Edition to compile C source code?

I wish to learn C so that I can understand the concepts behind many major programming languages without the shortcuts that C++ has, or the garbage collectors that Java has. I plan on learning C and then going to C++, and I am currently studying Computer Science.

In anycase, I was wondering if Visual C++ 2008 Express Edition 开发者_如何转开发compiler for a Windows machine would be able to compile C source. I would think so, as you can implement C into C++. Yet, when I try to create a file there is no C selection. I can create header files, but I am not sure which files I need for C or C++. I know minimal information.

If I can not compile C with that compiler, is there another compiler that I can compile C with?

Thanks.


It will compile source as a dialect of C89 if you save it with a .c extension.

It won't compile C99.


Just rename the file ".c" and it will compile in "C" mode.

Or right click the project select properties. Then navigate to Configuration Properties->C/C++->Advanced and set the "Compile As" to "Compile as C code (/TC"). The bit in the brackets is the commandline switch should you want to use it.


Yes, you can.

If you give ".c" extension to a source file it'll be compiled as C code.

You can also specify compilation mode (C or C++) in project options (for a whole project) or file options (for a certain file).


Not a problem, VC has a C89 compatible C compiler. It autodetects the language from the file name extension, a .c file will be compiled as C. Or you force it by right-clicking the file, Properties, C/C++, Advanced, Compile As = /TC. Avoid that.

When you start out with the Win32 Console Application project template then you'll need to make a few changes. The template was designed assuming you'd use C++. Right-click stdafx.cpp, Rename to stdafx.c. Repeat on the project's .cpp file. Everything will now be compiled as C, including support for precompiled headers.

There's something to be said for starting in C++ right away btw. Maybe a good topic for another question.


Something else worth mentioning, you should be able to compile C code as C++ with no problems. You may have problems linking if you are using external code as the C++ compiler will use a different calling convention (and name mangling), but that shouldn't be a problem if you are just using your own code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜