Section 18. Tools and Resources 18.1: I need: A: Look for programs (see also question 18.16) named: a C cross-reference cflow, cxref, calls, cscope, generator xscope, or ixfw a C beautifier/pretty- cb, indent, GNU indent, or printer vgrind a revision control or CVS, RCS, or SCCS configuration management tool a C source obfuscator obfus, shroud, or opqcp (shrouder) a "make" dependency makedepend, or try cc -M or generator cpp -M tools to compute code ccount, Metre, lcount, or csize, metrics or see URL http://www.qucis.queensu.ca/ Software-Engineering/Cmetrics.html ; there is also a package sold by McCabe and Associates a C lines-of-source this can be done very counter crudely with the standard Unix utility wc, and somewhat better with grep -c ";" a C declaration aid check volume 14 of (cdecl) comp.sources.unix (see question 18.16) and K&R2 a prototype generator see question 11.31 a tool to track down malloc problems see question 18.2 a "selective" C preprocessor see question 10.18 language translation see questions 11.31 and tools 20.26 C verifiers (lint) see question 18.7 a C compiler! see question 18.3 (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. 18.2: 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; and MEMDEBUG from ftp.crpht.lu in pub/sources/memdebug . 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: Bounds-Checker for DOS, from Nu-Mega Technologies, P.O. Box 7780, Nashua, NH 03060-7780, USA, 603-889-2386. CodeCenter (formerly Saber-C) from Centerline Software, 10 Fawcett Street, Cambridge, MA 02138, USA, 617-498-3000. Insight, from ParaSoft Corporation, 2500 E. Foothill Blvd., Pasadena, CA 91107, USA, 818-792-9941, insight@parasoft.com . Purify, from Pure Software, 1309 S. Mary Ave., Sunnyvale, CA 94087, USA, 800-224-7873, http://www.pure.com , info-home@pure.com . (I believe Pure was recently acquired by Rational.) Final Exam Memory Advisor, from PLATINUM Technology (formerly Sentinel from AIB Software), 1815 South Meyers Rd., Oakbrook Terrace, IL 60181, USA, 630-620-5000, 800-442-6861, info@platinum.com, www.platinum.com . ZeroFault, from The Kernel Group, 1250 Capital of Texas Highway South, Building Three, Suite 601, Austin, TX 78746, 512-433-3333, http://www.tkg.com, zf@tkg.com . 18.3: 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. It is available by anonymous ftp from prep.ai.mit.edu in directory pub/gnu, or at several other FSF archive sites. An MS-DOS port, djgpp, is also available; see the djgpp home page at http://www.delorie.com/djgpp/ . There is a shareware compiler called PCC, available as PCC12C.ZIP . A very inexpensive MS-DOS compiler is Power C from Mix Software, 1132 Commerce Drive, Richardson, TX 75801, USA, 214-783-6001. Another recently-developed compiler is lcc, available for anonymous ftp from ftp.cs.princeton.edu in pub/lcc/. A shareware MS-DOS C compiler is available from ftp.hitech.com.au/hitech/pacific. Registration is optional for non-commercial use. There are currently no viable shareware compilers for the Macintosh. Archives associated with comp.compilers contain a great deal of information about available compilers, interpreters, grammars, etc. (for many languages). The comp.compilers archives (including an FAQ list), maintained by the moderator, John R. Levine, are at iecc.com . A list of available compilers and related resources, maintained by Mark Hopkins, Steven Robenalt, and David Muir Sharnoff, is at ftp.idiom.com in pub/compilers- list/. (See also the comp.compilers directory in the news.answers archives at rtfm.mit.edu and ftp.uu.net; see question 20.40.) See also question 18.16. 18.4: 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). Many C compilers are really only half- compilers, electing not to diagnose numerous source code difficulties which would not actively preclude code generation. See also questions 16.5, 16.8, and 18.7. References: Ian Darwin, _Checking C Programs with lint_ . 18.5: How can I shut off the "warning: possible pointer alignment problem" message which lint gives me for each call to malloc()? A: The problem is that traditional versions of lint do not know, and cannot be told, that malloc() "returns a pointer to space suitably aligned for storage of any type of object." It is possible to provide a pseudoimplementation of malloc(), using a #define inside of #ifdef lint, which effectively shuts this warning off, but a simpleminded definition will also suppress meaningful messages about truly incorrect invocations. It may be easier simply to ignore the message, perhaps in an automated way with grep -v. (But don't get in the habit of ignoring too many lint messages, otherwise one day you'll overlook a significant one.) 18.7: Where can I get an ANSI-compatible lint? A: Products called PC-Lint and FlexeLint (in "shrouded source form," for compilation on 'most any system) are available from Gimpel Software 3207 Hogarth Lane Collegeville, PA 19426 USA (+1) 610 584 4261 gimpel@netaxs.com 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 LCLint, available via anonymous ftp from larch.lcs.mit.edu in pub/Larch/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 .) 18.8: Don't ANSI function prototypes render lint obsolete? A: No. 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. If you do want to use function prototypes instead of lint for cross-file consistency checking, make sure that you set the prototypes up correctly in header files. See questions 1.7 and 10.6. 18.9: 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://members.xoom.com/tomtorfs/cintro.html . "Notes for C programmers," by Christopher Sawtell, are available from svr-ftp.eng.cam.ac.uk in misc/sawtell_C.shar and garbo.uwasa.fi in /pc/c-lang/c-lesson.zip . 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.swcp.com/~dodrill . Rick Rowe has a tutorial which is available from ftp.netcom.com as pub/rowe/tutorde.zip or ftp.wustl.edu as pub/MSDOS_UPLOADS/programming/c_language/ctutorde.zip . There is evidently a web-based course at http://www.strath.ac.uk/CC/Courses/CCourse/CCourse.html . 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 teaches a C class and has placed its 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.lysator.liu.se/c/index.html . 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 . See also questions 18.10 and 18.15c. 18.10: What's a good book for learning C? 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 Kernighan and 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, see e.g. http://www.csd.uwo.ca/~jamie/.Refs/.Footnotes/C-annotes.html, http://www.eskimo.com/~scs/cclass/cclass.html, and http://www.lysator.liu.se/c/c-errata.html#main . 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. Though not suitable for learning C from scratch, this FAQ list has been published in book form; see the Bibliography. Mitch Wright maintains an annotated bibliography of C and Unix books; it is available for anonymous ftp from ftp.rahul.net in directory pub/mitch/YABL/. Scott McMahon has a nice set of reviews at http://www.skwc.com/essent/cyberreviews.html . The Association of C and C++ Users (ACCU) maintains a comprehensive set of bibliographic reviews of C/C++ titles, at http://bach.cis.temple.edu/accu/bookcase or http://www.accu.org/accu . This FAQ list's editor has a large collection of assorted old recommendations which various people have posted; it is available upon request. See also question 18.9 above. 18.13: Where can I find the sources of the standard C libraries? A: One source (though not public domain) is _The Standard C Library_, by P.J. Plauger (see the Bibliography). Implementations of all or part of the C library have been written and are readily available as part of the NetBSD and GNU (also Linux) projects. See also questions 18.15c and 18.16. 18.13b: Is there an on-line C reference manual? A: Two possibilities are http://www.cs.man.ac.uk/standard_c/_index.html and http://www.dinkumware.com/htm_cl/index.html . 18.13c: Where can I get a copy of the ANSI/ISO C Standard? A: See question 11.2. 18.14: 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). 18.15: 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 (along with one for C++) by Jim Roskind is in pub/c++grammar1.1.tar.Z at ics.uci.edu (or perhaps ftp.ics.uci.edu, or perhaps OLD/pub/c++grammar1.1.tar.Z), or at ftp.eskimo.com in u/s/scs/roskind_grammar.Z . A fleshed-out, working instance of the ANSI 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). 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. References: 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. 18.15b: 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. 18.15c: Where are some collections of useful code fragments and examples? A: Bob Stout's popular "SNIPPETS" collection is available from ftp.brokersys.com in directory pub/snippets or on the web at http://www.brokersys.com/snippets/ . Lars Wirzenius's "publib" library is available from ftp.funet.fi in directory pub/languages/C/Publib/. See also questions 14.12, 18.9, 18.13, and 18.16. 18.15d: 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, the MIRACL package (see http://indigo.ie/~mscott/ ), 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. 18.16: 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 article 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. See also questions 14.12, 18.13, and 18.15c.