The C programming language

Overview

C is a programming language. The definitive book on C is The C Programming Language by Brian Kernighan and Dennis Ritchie (K&R). Dennis Ritchie was the designer of C.

An online reference can be found in cplusplus.com.

Note: despite its efficiency, flexibility and versatility, C is a somewhat tricky language for beginners (it is however but far less complicated than C++).

Getting started and compilers

Unix/Linux

Windows

If you use Microsoft Visual Studio, please check this link.

Basically, after setting up the environment variables, either manually or running vcvars32.bat in the VC folder, type cl hello.c which will produce an executable hello.exe

Besides the Microsoft Visual C++ compiler, there are a few free and smaller alternatives for Windows:

Tools

IDE / Debugger

Microsoft Visual Studio is a good IDE for Windows. Under Linux, I found Code::Blocks quite easy to use (similar to Visual C++ 6.0).

Make

An instruction file, typically Makefile, to assemble more than one source code files,

In Linux GNU Make is particularly useful as it has many extensions.

Memory check

Valgrind is a tool to check memory errors (e.g., array out of boundary, memory leaks). Compile your code with gcc -O0 -g3 foo.c or at least gcc -g foo.c option. Then run the program with valgrind ./a.out. Errors, if any, will be reported during the run.

Profiler

A profiler reports where your program spends most of the time. To use it in GCC, do the follows,

  1. Compile with: gcc -pg foo.c
  2. Run the program normally: ./a.out
  3. Check the report: gprof a.out

Version control

I use Git for version control. It pretty much does everything I need.

Code beautifier

Uncrustify is a decent program that changes the code style. A typical use is the following.

uncrustify -c my.cfg --replace target.c

Here -c my.cfg specifies the configuration file, my personal favorite is uncrustify.cfg. The flag --replace means to overwrite the input file, which is target.c.

Other resources

Pros and Cons

Pros:

Cons: