views:

103

answers:

5

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.

+1  A: 

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.

Goz
Thank you :) These are easy to follow instructions and I easily changed the settings.
Rick
@Rick: Well you could give me an upvote and accept my answer then :)
Goz
+1  A: 

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

adf88
+4  A: 

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

It won't compile C99.

Pete Kirkham
imho the most helpful answer
Hinek
+1  A: 

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.

Hans Passant
If I start with C++ I wouldn't understand what is going on behind the scenes that C++ does automatically. I also have no previous programming experience, so this would help me understand the routine procedures that programs need. I think.
Rick
I don't want to touch this with a ten-foot pole, but assuming that C is going to be helpful to learn C++ is questionable. They are very different languages. As I said, start a new question about it.
Hans Passant
A: 

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.

Dolphin
No, you can write a particular subset of C in a non-idiomatic way and C++ will compile it, but in general any C code with dynamic memory will exploit C's weaker type system and not have the casts which C++'s stiffer type system requires.
Pete Kirkham
um, so you are downvoting me because C++ requires an explicit cast from malloc?
Dolphin