Q: I need some C development tools.
A: Here is a crude list of some which are available.
(This list of tools is by no means complete; if you know of tools not mentioned, you're welcome to contact this list's maintainer.)
Other lists of tools, and discussion about them, can be found in the Usenet newsgroups comp.compilers and comp.software-eng.
See also questions 18.3 and 18.16.
Q: How can I track down these pesky malloc problems?
A: A number of debugging packages exist to help track down malloc problems; one popular one is Conor P. Cahill's ``dbmalloc'', posted to comp.sources.misc in 1992, volume 32. Others are ``leak'', available in volume 27 of the comp.sources.unix archives; JMalloc.c and JMalloc.h in the ``Snippets'' collection; MEMDEBUG from ftp.crpht.lu in pub/sources/memdebug ; and Electric Fence. See also question 18.16.
A number of commercial debugging tools exist, and can be invaluable in tracking down malloc-related and other stubborn problems:
Q: What's a free or cheap C compiler I can use?
A: A popular and high-quality free C compiler is the FSF's GNU C compiler, or gcc. An MS-DOS port, djgpp, is also available. As far as I know, there are versions of gcc for Macs and Windows machines, too.
A very inexpensive MS-DOS compiler is Power C from Mix Software, 1132 Commerce Drive, Richardson, TX 75801, USA, 214-783-6001.
A shareware MS-DOS C compiler is available from ftp.hitech.com.au/hitech/pacific. Registration is optional for non-commercial use.
Archives associated with the comp.compilers newsgroup contain a great deal of information about available compilers, interpreters, grammars, etc. (for many languages). The comp.compilers archives include an FAQ list and a catalog of free compilers.
See also question 18.16.
Q: I just typed in this program, and it's acting strangely. Can you see anything wrong with it?
A: See if you can run lint first (perhaps with the -a, -c, -h, -p or other options[footnote] ). Many C compilers are really only half-compilers, taking the attitude that it's not their problem if you didn't say what you meant, or if what you said is virtually guaranteed not to work. (But do also see if your compiler has extra warning levels which can be optionally requested.)
References: Ian Darwin, Checking C Programs with lint
Q: How can I shut off the ``warning: possible pointer alignment problem'' message which lint gives me for each call to malloc?
A: A modern lint shouldn't be complaining about this.
Once upon a time, lint did not and could not know that malloc ``returns a pointer to space suitably aligned for storage of any type of object.'' There were various kludgey workarounds for this problem, but today, the void * type exists precisely to encapsulate the notion of a ``generic'' pointer, and an ANSI-compatible lint should understand this.
Q: Can I declare main as void, to shut off these annoying ``main returns no value'' messages?
A: No. See question 11.12b.
Q: Where can I get an ANSI-compatible lint?
The Unix System V release 4 lint is ANSI-compatible, and is available separately (bundled with other C tools) from UNIX Support Labs or from System V resellers.
Another ANSI-compatible lint (which can also perform higher-level formal verification) is Splint (formerly lclint).
In the absence of lint, many modern compilers do attempt to diagnose almost as many problems as lint does. (Many netters recommend gcc -Wall -pedantic [footnote] .)
Q: Don't ANSI function prototypes render lint obsolete?
A: Not really. First of all, prototypes work only if they are present and correct; an inadvertently incorrect prototype is worse than useless. Secondly, lint checks consistency across multiple source files, and checks data declarations as well as functions. Finally, an independent program like lint will probably always be more scrupulous at enforcing compatible, portable coding practices than will any particular, implementation-specific, feature- and extension-laden compiler.
Q: Are there any C tutorials or other resources on the net?
A: There are several of them:
Tom Torfs has a nice tutorial at http://cprog.tomsweb.net.
Tim Love's ``C for Programmers'' is available by ftp from svr-ftp.eng.cam.ac.uk in the misc directory. An html version is at http://www-h.eng.cam.ac.uk/help/tpl/languages/C/teaching_C/teaching_C.html.
The Coronado Enterprises C tutorials are available on Simtel mirrors in pub/msdos/c or on the web at http://www.coronadoenterprises.com/tutorials/c/index.html.
There is a web-based course by Steve Holmes at http://www.strath.ac.uk/IT/Docs/Ccourse/.
Martin Brown has C course material on the web at http://www-isis.ecs.soton.ac.uk/computing/c/Welcome.html.
On some Unix machines you can try typing ``learn c'' at the shell prompt (but the lessons may be quite dated).
Finally, the author of this FAQ list once taught a couple of C classes and has placed their notes on the web; they are at http://www.eskimo.com/~scs/cclass/cclass.html.
[Disclaimer: I have not reviewed many of these tutorials, and I gather that they tend to contain errors. With the exception of the one with my name on it, I can't vouch for any of them. Also, this sort of information rapidly becomes out-of-date; these addresses may not work by the time you read this and try them.]
Several of these tutorials, plus a great deal of other information about C, are accessible via the web at http://www.quut.com/c/.
Vinit Carpenter maintains a list of resources for learning C and C++; it is posted to comp.lang.c and comp.lang.c++, and archived where this FAQ list is (see question 20.40), or on the web at http://www.cyberdiem.com/vin/learn.html.
Q: Where can I find some good code examples to study and learn from?
A: Although studying existing source code is indeed a very good way of learning, it's unfortunately hard to recommend any truly good examples, because so much of the actual code out there is either pedagogical (i.e. not real-world), or all too real-world (i.e. too voluminous and complicated for mere mortals to understand).
With that said, here are a couple of links to explore:
A word of warning: there is some excellent code out there to learn from, but there is plenty of truly bletcherous code, too. If you find yourself perusing some code which is scintillatingly clear and which accomplishes its task as easily as it ought to (if not more so), do learn everything you can from that code. But if you come across some code that is unmanageably confusing, that seems to be operating with ten bandaged thumbs and boxing gloves on, please do not imagine that that's the way it has to be; if nothing else, walk away from such code having learned only that you're not going to commit any such atrocities yourself.
Q: What's a good book for learning C? What about advanced books and references?
A: There are far too many books on C to list here; it's impossible to rate them all. Many people believe that the best one was also the first: The C Programming Language, by Brian Kernighan and Dennis Ritchie (``K&R,'' now in its second edition). Opinions vary on K&R's suitability as an initial programming text: many of us did learn C from it, and learned it well; some, however, feel that it is a bit too clinical as a first tutorial for those without much programming background. Several sets of annotations and errata are available on the net, by J. Blustein, this FAQ list's author, and K&R themselves.
Many comp.lang.c regulars recommend C: A Modern Approach, by K.N. King.
An excellent reference manual is C: A Reference Manual, by Samuel P. Harbison and Guy L. Steele, now in its fourth edition.
The Association of C and C++ Users (ACCU) maintains a comprehensive set of bibliographic reviews of C/C++ titles.
See also question 18.9.
Additional links: Ian Hay's recommended book list
Q: Where can I find answers to the exercises in K&R?
Q: Does anyone know where the source code from books like Numerical Recipes in C, Plauger's The Standard C Library, or Kernighan and Pike's The UNIX Programming Environment is available on-line?
A: Books containing large quantities of potentially-useful source code, including the ones mentioned in the question, usually make explicit mention of the availability of source code and policies for its use. Published source code is copyrighted, and may generally not be used, or especially redistributed, without permission (and perhaps a few restrictions, though presumably the publisher doesn't mind your typing it in for personal use). Often a diskette is available from the publisher; also, many publishers have set up ftp sites and web pages.
Some of the routines from Numerical Recipes have been released to the public domain; see the Numerical Recipes website for details.
Q: Where can I find the sources of the standard C libraries?
A: The GNU project has a complete implementation at http://www.gnu.org/software/libc/. Another source (though not public domain) is The Standard C Library, by P.J. Plauger (see the Bibliography). See also questions 18.9b, 18.15c, and 18.16.
Q: Is there an on-line C reference manual?
Q: Where can I get a copy of the ANSI/ISO C Standard?
A: See question 11.2.
Q: I need code to parse and evaluate expressions.
A: Two available packages are ``defunc,'' posted to comp.sources.misc in December, 1993 (V41 i32,33), to alt.sources in January, 1994, and available from sunsite.unc.edu in pub/packages/development/libraries/defunc-1.3.tar.Z, and ``parse,'' at lamont.ldgo.columbia.edu. Other options include the S-Lang interpreter, available via anonymous ftp from amy.tch.harvard.edu in pub/slang, and the shareware Cmm (``C-minus-minus'' or ``C minus the hard stuff''). See also questions 18.16 and 20.6.
There is also some parsing/evaluation code in Software Solutions in C (chapter 12, pp. 235-55).
Q: Where can I get a BNF or YACC grammar for C?
A: The definitive grammar is of course the one in the ANSI standard; see question 11.2. Another grammar by Jim Roskind is available at ftp.eskimo.com in u/s/scs/roskind_grammar.Z. A fleshed-out, working instance of the ANSI C90 grammar (due to Jeff Lee) is on ftp.uu.net (see question 18.16) in usenet/net.sources/ansi.c.grammar.Z (including a companion lexer). [footnote] The FSF's GNU C compiler contains a grammar, as does the appendix to K&R2.
The comp.compilers archives contain more information about grammars; see question 18.3.
K&R1 Sec. A18 pp. 214-219
K&R2 Sec. A13 pp. 234-239
ISO Sec. B.2
H&S pp. 423-435 Appendix B
Q: Does anyone have a C compiler test suite I can use?
A: Plum Hall (formerly in Cardiff, NJ; now in Hawaii) sells one; other packages are Ronald Guilmette's RoadTest(tm) Compiler Test Suites (ftp to netcom.com, pub/rfg/roadtest/announce.txt for information) and Nullstone's Automated Compiler Performance Analysis Tool (see http://www.nullstone.com). The FSF's GNU C (gcc) distribution includes a c-torture-test which checks a number of common problems with compilers. Kahan's paranoia test, found in netlib/paranoia on netlib.att.com, strenuously tests a C implementation's floating point capabilities.
Q: Where are some collections of useful code fragments and examples?
Q: I need code for performing multiple precision arithmetic.
A: Some popular packages are the ``quad'' functions within the BSD Unix libc sources (ftp.uu.net, /systems/unix/bsd-sources/.../src/lib/libc/quad/*), the GNU MP library ``libmp'', the MIRACL package (see http://indigo.ie/~mscott/), the ``calc'' program by David Bell and Landon Curt Noll, and the old Unix libmp.a. See also questions 14.12 and 18.16.
References: Schumacher, ed., Software Solutions in C Sec. 17 pp. 343-454
Q: Where and how can I get copies of all these freely distributable programs?
A: As the number of available programs, the number of publicly accessible archive sites, and the number of people trying to access them all grow, this question becomes both easier and more difficult to answer.
There are a number of large, public-spirited archive sites out there, such as ftp.uu.net, archive.umich.edu, oak.oakland.edu, sumex-aim.stanford.edu, and wuarchive.wustl.edu, which have huge amounts of software and other information all freely available. For the FSF's GNU project, the central distribution site is prep.ai.mit.edu. These well-known sites tend to be extremely busy and hard to reach, but there are also numerous ``mirror'' sites which try to spread the load around.
On the connected Internet, the traditional way to retrieve files from an archive site is with anonymous ftp. For those without ftp access, there are also several ftp-by-mail servers in operation. More and more, the world-wide web (WWW) is being used to announce, index, and even transfer large data files. There are probably yet newer access methods, too.
Those are some of the easy parts of the question to answer. The hard part is in the details--this document cannot begin to track or list all of the available archive sites or all of the various ways of accessing them. If you have access to the net at all, you probably have access to more up-to-date information about active sites and useful access methods than this FAQ list does.
The other easy-and-hard aspect of the question, of course, is simply finding which site has what you're looking for. There is a tremendous amount of work going on in this area, and there are probably new indexing services springing up every day. One of the first was ``archie'', and of course there are a number of high-profile commercial net indexing and searching services such as Alta Vista, Excite, and Yahoo.
If you have access to Usenet, see the regular postings in the comp.sources.unix and comp.sources.misc newsgroups, which describe the archiving policies for those groups and how to access their archives, two of which are ftp://gatekeeper.dec.com/pub/usenet/comp.sources.unix/ and ftp://ftp.uu.net/usenet/comp.sources.unix/. The comp.archives newsgroup contains numerous announcements of anonymous ftp availability of various items. Finally, the newsgroup comp.sources.wanted is generally a more appropriate place to post queries for source availability, but check its FAQ list, ``How to find sources,'' before posting there.
Q: Where can I get extra copies of this list?
A: See question 20.40.