Frequently Asked Questions in comp.lang.c

[Last modified March 1, 1993 by scs.]

Certain topics come up again and again on this newsgroup. They are good questions, and the answers may not be immediately obvious, but each time they recur, much net bandwidth and reader time is wasted on repetitive responses, and on tedious corrections to the incorrect answers which are inevitably posted.

This article, which is posted monthly, attempts to answer these common questions definitively and succinctly, so that net discussion can move on to more constructive topics without continual regression to first principles.

No mere newsgroup article can substitute for thoughtful perusal of a full-length tutorial or language reference manual. Anyone interested enough in C to be following this newsgroup should also be interested enough to read and study one or more such manuals, preferably several times. Some C books and compiler manuals are unfortunately inadequate; a few even perpetuate some of the myths which this article attempts to refute. Several noteworthy books on C are listed in this article's bibliography. Many of the questions and answers are cross-referenced to these books, for further study by the interested and dedicated reader (but beware of ANSI vs. ISO C Standard section numbers; see question 5.1).

If you have a question about C which is not answered in this article, first try to answer it by checking a few of the referenced books, or by asking knowledgeable colleagues, before posing your question to the net at large. There are many people on the net who are happy to answer questions, but the volume of repetitive answers posted to one question, as well as the growing number of questions as the net attracts more readers, can become oppressive. If you have questions or comments prompted by this article, please reply by mail rather than following up -- this article is meant to decrease net traffic, not increase it.

Besides listing frequently-asked questions, this article also summarizes frequently-posted answers. Even if you know all the answers, it's worth skimming through this list once in a while, so that when you see one of its questions unwittingly posted, you won't have to waste time answering.

This article is always being improved. Your input is welcomed. Send your comments to scs@eskimo.com .

The questions answered here are divided into several categories:

  1. Null Pointers
  2. Arrays and Pointers
  3. Memory Allocation
  4. Expressions
  5. ANSI C
  6. C Preprocessor
  7. Variable-Length Argument Lists
  8. Boolean Expressions and Variables
  9. Structs, Enums, and Unions
  10. Declarations
  11. Stdio
  12. Library Subroutines
  13. Lint
  14. Style
  15. Floating Point
  16. System Dependencies
  17. Miscellaneous (Fortran to C converters, YACC grammars, etc.)

Bibliography

ANSI
American National Standard for Information Systems -- Programming Language -- C, ANSI X3.159-1989 (see question 5.2).
JLB
Jon Louis Bentley, Writing Efficient Programs, Prentice-Hall, 1982, ISBN 0-13-970244-X.
H&S
Samuel P. Harbison and Guy L. Steele, C: A Reference Manual, Second Edition, Prentice-Hall, 1987, ISBN 0-13-109802-0. (A third edition has recently been released.)
PCS
Mark R. Horton, Portable C Software, Prentice Hall, 1990, ISBN 0-13-868050-7.
EoPS
Brian W. Kernighan and P.J. Plauger, The Elements of Programming Style, Second Edition, McGraw-Hill, 1978, ISBN 0-07-034207-5.
K&R I
Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, Prentice-Hall, 1978, ISBN 0-13-110163-3.
K&R II
Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, Second Edition, Prentice-Hall, 1988, ISBN 0-13- 110362-8, 0-13-110370-9.
Knuth
Donald E. Knuth, The Art of Computer Programming, (3 vols.), Addison-Wesley, 1981.
CT&P
Andrew Koenig, C Traps and Pitfalls, Addison-Wesley, 1989, ISBN 0-201-17928-8.

P.J. Plauger, The Standard C Library, Prentice Hall, 1992, ISBN 0-13-131509-9.

Harry Rabinowitz and Chaim Schaap, Portable C, Prentice-Hall, 1990, ISBN 0-13-685967-4.

There is a more extensive bibliography in the revised Indian Hill style guide (see question 14.3). See also question 17.31.

Acknowledgements

Thanks to Jamshid Afshar, Sudheer Apte, Randall Atkinson, Dan Bernstein, Vincent Broman, Stan Brown, Joe Buehler, Gordon Burditt, Burkhard Burow, Conor P. Cahill, D'Arcy J.M. Cain, Christopher Calabrese, Ian Cargill, Paul Carter, Raymond Chen, Jonathan Coxhead, Lee Crawford, Steve Dahmer, Andrew Daviel, James Davies, Jutta Degener, Norm Diamond, Jeff Dunlop, Ray Dunn, Stephen M. Dunn, Michael J. Eager, Dave Eisen, Bjorn Engsig, Chris Flatters, Rod Flores, Alexander Forst, Jeff Francis, Dave Gillespie, Samuel Goldstein, Alasdair Grant, Ron Guilmette, Doug Gwyn, Tony Hansen, Joe Harrington, Guy Harris, Elliotte Rusty Harold, Jos Horsmeier, Blair Houghton, Ke Jin, Kirk Johnson, Larry Jones, Kin-ichi Kitano, Peter Klausler, Andrew Koenig, Tom Koenig, Ajoy Krishnan T, Markus Kuhn, John Lauro, Felix Lee, Mike Lee, Timothy J. Lee, Tony Lee, Don Libes, Christopher Lott, Tim Love, Tim McDaniel, Stuart MacMartin, John R. MacMillan, Bob Makowski, Evan Manning, Barry Margolin, George Matas, Brad Mears, Bill Mitchell, Mark Moraes, Darren Morby, Ken Nakata, Landon Curt Noll, David O'Brien, Richard A. O'Keefe, Hans Olsson, Philip (lijnzaad@embl-heidelberg.de), Christopher Phillips, Francois Pinard, Dan Pop, Kevin D. Quitt, Pat Rankin, J. M. Rosenstock, Erkki Ruohtula, Tomohiko Sakamoto, Rich Salz, Chip Salzenberg, Paul Sand, DaviD W. Sanderson, Christopher Sawtell, Paul Schlyter, Doug Schmidt, Rene Schmit, Patricia Shanahan, Peter da Silva, Joshua Simons, Henry Spencer, David Spuler, Melanie Summit, Erik Talvola, Clarke Thatcher, Wayne Throop, Chris Torek, Andrew Tucker, Goran Uddeborg, Rodrigo Vanegas, Jim Dan Pop, Kevin D. Quitt, Pat Rankin, J. M. Rosenstock, Erkki Ruohtula, Tomohiko Sakamoto, Rich Salz, Chip Salzenberg, Paul Sand, DaviD W. Sanderson, Christopher Sawtell, Paul Schlyter, Doug Schmidt, Rene Schmit, Patricia Shanahan, Peter da Silva, Joshua Simons, Henry Spencer, David Spuler, Melanie Summit, Erik Talvola, Clarke Thatcher, Wayne Throop, Chris Torek, Andrew Tucker, Goran Uddeborg, Rodrigo Vanegas, Jim Van Zandt, Wietse Venema, Ed Vielmetti, Larry Virden, Chris Volpe, Mark Warren, Larry Weiss, Freek Wiedijk, Lars Wirzenius, Dave Wolverton, Mitch Wright, Conway Yee, and Zhuo Zang, who have contributed, directly or indirectly, to this article. Special thanks to Karl Heuer, and particularly to Mark Brader, who (to borrow a line from Steve Johnson) have goaded me beyond my inclination, and occasionally beyond my endurance, in relentless pursuit of a better FAQ list.

Steve Summit
scs@eskimo.com

This article is Copyright 1988, 1990-1994 by Steve Summit. It may be freely redistributed so long as the author's name, and this notice, are retained.
The C code in this article (vstrcat(), error(), etc.) is public domain and may be used without restriction.


The HTML annotation of this FAQ was done in March 1994 by Jutta Degener.
[down] [subview]