Here is a collection of annotated references and web-page links, together with a bit of material of my own, on the general topic of the C programming language.
Table of Contents:
Link to my web page on C++ programming.
Link to my web page on numerical programming.
Link back to my home page.
C is a relatively small, simple, language, designed for ease of use, flexibility, and low-level efficiency. It's fairly easy to learn, though it requires a more sophisticated "mental model" of what the computer is doing than (say) Fortran or Basic.
C was designed by and for use by reasonably skilled programmers, and specifically does not offer very many "training wheels" or "safety guards" features. That is, C generally assumes that you (the programmer) know what you're doing, and it offers few safeguards against (a program) trying to do silly or invalid things. This is both an advantage (the language doesn't get in your way when you want to do fancy things) and a disadvantage (if you do something silly by mistake, the language won't try to stop you). Caveat programmer!
I recommend the GNU Project's GNU Compiler Collection, commonly known as gcc. This is an excellent compiler which actually handles C, C++, Fortran, Java, Chill, Ada, and maybe also some other languages I don't remember right now. gcc is much closer to the official C/C++ language standards than Microsoft's compilers, for example. [In fact Microsoft's compilers are notorious for egregious violations of the language standards -- Microsoft's business model doesn't call for making it easy for their users to switch to other vendors. :( ]
You can download a GCC source distribution from the GCC web pages. If you're using a Unix-flavored computer system and you have at least a little computer background, this is the best way to get an up-to-date compiler. (Since gcc is written in C, you'll need some existing C compiler (just about any one will do) to bootstrap the process. But that shouldn't be a problem -- most Unix-flavored systems already come with a C compiler, or if not you should be able to find binaries of some older gcc version somewhere on the net.)
If you're stuck with Microsoft Windows in any of its incarnations, there are a couple of different GCC ports available, which you can download as binary distributions. Two good ones are
Kernighan and Ritchie,
The C Programming Language, 2nd Edition
This is the granddaddy of all C books (Ritchie was the original
inventor/designer of C), and in my opinion it's still the best general
book from which to learn C, at least for readers who already know the
basic concepts of programming in some other language.
Harbison and Steele,
C: A Reference Manual, 5th Edition,
If Kernighan and Ritchie should be your first C book, then this should
be your second or third. It's not a book from which you'd want to
learn C, but rather a superb reference book for C,
focusing on the more advanced and tricky parts. This book is my personal
favorite for a reference book to keep within arms's reach while programming
in C.
As a general rule of thumb, I strongly recommend avoiding any book in the following categories:
come.lang.c Frequently Asked Questions List
This is the online version of Steve Summit's superb
Frequently-Asked-Questions list for the comp.lang.c
Usenet newsgroup. It covers a lot of frequently-confused topics in
C, mostly fairly elementary ones, and I recommend that anyone doing
nontrivial C programming at least skim through it.
A Tutorial on Pointers and Arrays in C
An expanded tutorial on this famously-confusing-to-beginning-C-programmers
subject. I haven't read through it in detail, but it looks pretty good.
Notes for Steve Summit's Introductory C Programming Class
These notes are for courses in C programming which the author teaches
at the University of Washington (Seattle, USA). A number of people have
recommended them as very useful in their own right if you're trying to
learn C.
alt.comp.lang.learn-c Frequently Asked Questions List
This is an FAQ list devoted to questions about learning C
or C++. It has lots of references and links to other resources, web
sites, and assorted information for the beginning C/C++ programmer.
My Web Page on C Function Pointers
This is a very simple example I wrote to demonstrate the use of
function pointers in C.
/* NOTREACHED */ or Real Programs Dump Core
This is a superb paper, originally published in a mid-1980s Usenix
conference proceedings, on some of the careless things that programmers
often do (or neglect to do), which cause core dumps, crashes, and other
unpleasant behavior. You'll giggle a lot when reading this... except
for the spots where you realise that some of your own code contains
the same blunders ;=(.
Henry Spencer's
How To Steal Code or Inventing The Wheel Only Once
Some excellent advice by a net.god on how to use the standard library
instead of trying to re-invent the wheel.
Rob Pike's
Notes on Programming in C
This is a short, pithy, and very good essay on C programming style,
written by one of the best C programmers in the world. Most of it would
be equally relevant to any other language, too.
Henry Spencer's
The Ten Commandments for C Programmers
Another short, pithy, and very good essay on C programming style,
written by another one of the best C programmers in the world. This
is written in a pseudo-biblical style, and is a bit dated (it predates
the widespread availability of ISO (ANSI) C prototypes), but there's
still a lot of wisdom in it.
The Indian Hill Style Guide
Another famous style guide for C programming.
My Web Page on Calling Fortran Subroutines from C
A lot of excellent numerical software is written in Fortran, so it's
often useful to use this software (i.e. to call Fortran subroutines
and/or functions) from C and/or C++ programs. This is a web page I
wrote on how to do this (C only, not C++), as well as how to write
C functions which can be called from Fortran code.
Lysator Programming in C Web Page
This web page, hosted by Lysator (an academic computer society in Sweden)
has a nicely annotated collection of links to assorted resources on
C programming. These are generally aimed at fairly advanced programmers.
Peter Seebach's Joke
come.lang.c Infrequently Asked Questions List
This is a joke parody of the "legitimate"
come.lang.c Frequently Asked Questions List.
The answers to the IFAQ are all misleadingly wrong, or they're right for
totally wrong (and very misleading) reasons. Reading this list is good
for quite a few laughs (assuming you know enough C to spot the gotchas),
and trying to spot all the wrong and/or misleading statements might even
be a good exercise. Enjoy...
Brian W. Kernighan's paper
Why Pascal Is Not My Favorite Programming Language
(text)
(postscript)
A strongly opinionated discussion of why Pascal is ill-suited for
anything beyond toy problems, and (implicitly) why C is a much better
programming language. Note the date: this was written in 1981, when
Pascal commanded a much larger "mind share" among programmers than it
does today. This was originally published as Bell Labs
Computing Science Technical Report number 100.
Ed Post's article Real Programmers don't use Pascal
This is a famous tongue-in-cheek article, which originally appeared
in Datamation magazine in 1983, on why "Real Programmers"
use Fortran instead of Pascal. Entertaining, but don't take it --
or its stereotypes -- seriously...
Dennis Ritchie's Home Page
Among other accomplishments, Dennis Ritchie (a.k.a. dmr)
codesigned/invented Unix (here's his great paper on early Unix history,
The Evolution of the Unix Time-sharing System)
and designed/invented C (here's his
HOPL-II paper on the early history of C).
There are other lots of goodies and historical stuff on his web page,
too. He also has some funny stuff. My favorites for chuckles included
My undergraduate experience convinced me that I was not smart enough to be a physicist, and that computers were quite neat.
Brian Kernighan's Home Page
Another collection of Brian Kernighan's work and related topics
Another Unix/C old-timer still going strong!
The International Obfuscated C Code Contest
Quoting from the web page, the goals of the IOCCC are
The Underhanded C Contest
This is a contest to
write innocent-looking C code implementing malicious behavior. In many ways this is the exact opposite of the Obfuscated C Code Contest: in this contest you must write code that is as readable, clear, innocent and straightforward as possible, and yet it must fail to perform at its apparent function. To be more specific, it should do something subtly evil.Every year, we will propose a challenge to coders to solve a simple data processing problem, but with covert malicious behavior. Examples include miscounting votes, shaving money from financial transactions, or leaking information to an eavesdropper. The main goal, however, is to write source code that easily passes visual inspection by other programmers.
Link back to Jonathan Thornburg's home page.
$Revision: 1.4 $ of $Date: 2006/04/06 10:54:01 $.