Question:
Compiler for C (not c++)?
2012-07-22 15:00:08 UTC
I would like to program in C (the original c, not c++), but cannot find a compiler. It looks to me as if all the c compilers have been transformed into c++ compilers. I need to learn C to program a microprocessor, so I can only program in C. Is there an easy to use program that will create, run, save, and debug C files? I have tried using Visual Studio but have found it unhelpful. I would appreciate a list of both programs that are both free and not free. Thanks
Three answers:
Cubbi
2012-07-23 20:50:54 UTC
Microsoft abandoned C a long time ago. While Visual Studio comes with a C compiler (as mentioned, it is automatically invoked whenever you compile a .c file in a C++ project), that compiler only supports the doubly obsolete, 1989 version of C.

For your practice on a PC, get Intel C/C++ or GNU gcc/mingw, or pretty much anything besides Microsoft.
husoski
2012-07-22 15:32:08 UTC
Visual C++ is a C compiler, too. To create a C project:



1. Create an empty C++ project (don't worry, it will be C). Not a console project, Empty Project.



2. Add a new item. Use the toolbar button, the Project>Add New Item..., or right click on the project in the Solution Explorer and Add>New Item...



3. Select C++ Source File. (still don't worry) BUT... type the file name with a .c extension in the Name box. For example, don't just type "hello", type "hello.c". Then click Add.



That's it. Type or paste code and compile. You have a C project. VC++ supports ISO C90, with a number of features (but not all) from the C99 specification. I don't know of a free fully C99 compliant compiler.



If you have any GNU C++ compiler, you also have the GNU C compiler. Unlike VC++, separate commands are used to launch the compilers, but GCC (the C complier) is part of the core package that all other GNU compilers use. You can use Code::Blocks on Windows, Mac, Linux or Unix, and it asks C or C++ when you start a new project.
peteams
2012-07-22 15:34:44 UTC
Visual C++ and other compilers will compile source as C if the file name ends with .c rather than .cpp or .cxx.



I would also question why you don't want to use C++? Professional software development of stuff that is C-like tends to be compiled using a C++ compiler in full C++ mode because it offers many extra compile time checks. That is to say a C++ compiler can tell you your program has problems when it compiles it without you having to find the problems yourself through extensive testing and debugging.



C++ is pretty much a superset of C (there are some differences). You are not forced to use the parts of the superset in your application, you can stick to C. Indeed you can wrap your code in extern "C" { } to get the C experience even within otherwise C++ code.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...