Comp.Lang.C Frequently Asked Questions
Total Page:16
File Type:pdf, Size:1020Kb
comp.lang.c Frequently Asked Questions comp.lang.c Frequently Asked Questions This collection of hypertext pages is Copyright 1995 by Steve Summit. Content from the book ``C Programming FAQs: Frequently Asked Questions'' (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by permission of the author and the publisher as a service to the community. It is intended to complement the use of the published text and is protected by international copyright laws. The content is made available here and may be accessed freely for personal use but may not be published or retransmitted without written permission. This page is the top of an HTML version of the Usenet comp.lang.c Frequently Asked Questions (FAQ) list. An FAQ list is a collection of questions commonly asked on Usenet, together with presumably definitive answers, provided in an attempt to keep repeated questions on the newsgroup down to a low background drone so that discussion can move on to more interesting matters. Since they distill knowledge gleaned from many sources and answer questions which are demonstrably Frequent, FAQ lists serve as useful references outside of their originating Usenet newsgroups. This list is, I dare to claim, no exception, and the HTML version you're looking at now, as well as other versions referenced just below, are intended to be useful to C programmers everywhere. Several other versions of this FAQ list are available, including a book-length version published by Addison-Wesley. (The book, though longer, also has a few more errors; I've prepared an errata list.) See also question 20.40. Like so many web pages, this is very much a ``work in progress.'' I would, of course, like it if it were perfect, but it's been two years or so since I first started talking about putting this thing on the web, and if I were to wait until all the glitches were worked out, you might never see it. Each page includes a ``mail feedback'' button, so you can help me debug it. (At first, you don't have to worry about reporting minor formatting hiccups; many of these result from lingering imperfections in the programs that generate these pages, or from the fact that I have not exhaustively researched how various browsers implement the HTML tags I'm using, or from the fact that I haven't gone the last yard in trying to rig up HTML that looks good in spite of the fact that HTML doesn't have everything you need to make things look good.) These pages are synchronized with the posted Usenet version and the Addison- Wesley book version. Since not all questions appear in all versions, the question numbers are not always contiguous. http://www.eskimo.com/~scs/C-faq/top.html (1 of 3) [26/03/2003 11:39:58 p.m.] comp.lang.c Frequently Asked Questions [Note to web authors, catalogers, and bookmarkers: the URL <http://www.eskimo.com/~scs/C-faq/top.html> is the right way to link to these pages. All other URL's implementing this collection are subject to change.] You can browse these pages in at least three ways. The table of contents below is of the list's major sections; these links lead to sub-lists of the questions for those sections. The ``all questions'' link leads to a list of all the questions; each question is (obviously) linked to its answer. Finally, the ``read sequentially'' link leads to the first question; you can then follow the ``next'' link at the bottom of each question's page to read through all of the questions and answers sequentially. Steve Summit [email protected] 1. Declarations and Initializations 2. Structures, Unions, and Enumerations 3. Expressions 4. Pointers 5. Null Pointers 6. Arrays and Pointers 7. Memory Allocation 8. Characters and Strings 9. Boolean Expressions and Variables 10. C Preprocessor 11. ANSI/ISO Standard C http://www.eskimo.com/~scs/C-faq/top.html (2 of 3) [26/03/2003 11:39:58 p.m.] comp.lang.c Frequently Asked Questions 12. Stdio 13. Library Functions 14. Floating Point 15. Variable-Length Argument Lists 16. Strange Problems 17. Style 18. Tools and Resources 19. System Dependencies 20. Miscellaneous Bibliography Acknowledgements All Questions Read Sequentially http://www.eskimo.com/~scs/C-faq/top.html (3 of 3) [26/03/2003 11:39:58 p.m.] versions of comp.lang.c FAQ list comp.lang.c FAQ list(s) You probably just came from there, but there is a browsable, web-based HTML version. (Beware: as of 1999, the web-based version is somewhat out-of-date with respect to the plain-text versions below.) (Please don't ask me for a downloadable archive of the HTML version, as I'm currently unable to provide one. Just browse it here, or download one of the versions below.) An expanded, book-length version, with even longer answers to even more questions, has been published by Addison-Wesley (ISBN 0-201-84519-9). Printed books, alas, tend to have a few errors; I've prepared an errata list for this one. Here is a recent, compressed copy of the ASCII FAQ list, as posted to Usenet (~100k compressed, ~260k when uncompressed). This is currently the most up-to-date version. [This and the other compressed files ending in .Z referenced from this page are compressed with the Unix "compress" utility and can be uncompressed with "uncompress" or "gunzip", versions of which are, I believe, available for all popular operating systems.] Here is the abridged version (~26k compressed, ~55k when uncompressed). Here are the differences from the previous version (compressed, sometimes quite large; or maybe uncompressed, if they were minimal). Here is a collection of incremental differences with respect to even older versions. NOTE: All of these diff lists pertain to the versions posted to Usenet, which are not always synchronized with the web/html version. Here is a (considerably older) compressed, PostScript rendition (152k compressed). BEWARE: the question numbers don't match current versions. (Rather than printing it out, you could -- hint, hint -- get the book.) There are several translations into other languages: ● to German, by Jochen Schoof et al. (If that link doesn't work, try this one.) ● to Japanese, by Kinichi Kitano. (I don't know of a URL, but it is or was posted regularly to fj.comp.lang.c, and has been published by Toppan, ISBN 4-8101- 8097-2.) ● Seong-Kook Cin has completed a Korean translation, which is at http://pcrc.hongik.ac.kr/~cinsk/cfaqs/. http://www.eskimo.com/~scs/C-faq/versions.html (1 of 2) [26/03/2003 11:40:00 p.m.] versions of comp.lang.c FAQ list ● A French C FAQ list (not a direct translation of this one) is at http://www.isty- info.uvsq.fr/~rumeau/fclc/. Here is an, um, er, ``alternate version'' by Peter Seebach. If you're interested in C++, Marshall Cline maintains a C++ FAQ list. For web access to other Usenet FAQ lists, visit faqs.org. scs http://www.eskimo.com/~scs/C-faq/versions.html (2 of 2) [26/03/2003 11:40:00 p.m.] C Programming FAQs Errata Errata list for "C Programming FAQs: Frequently Asked Questions", by Steve Summit, Addison-Wesley, 1996, ISBN 0-201-84519-9 (first printing). A possibly more up-to-date copy of this errata list may be obtained at any time by anonymous ftp from ftp.eskimo.com in the file ~scs/C-faq/book/Errata, or on the web at http://www.eskimo.com/~scs/C-faq/book/Errata.html . (If you read this years from now and those addresses don't work, try ftp://ftp.aw.com/cseng/authors/summit/cfaq/ or http://www.awl.com/cseng/titles/0-201-84519-9 .) scs 2002-Oct-26 page question ---- -------- front cover The ladder has no rungs. xxix "woundn't" should be "wouldn't" 2 1.1 The fourth bulleted guarantee (about the sizes following the "obvious progression") is improperly stated. What the C Standard actually talks about, as in the rest of this answer, is just the ranges of the standard types, not their sizes in bits. So the real guarantees (as summarized below) are that sizeof(char) is at least 8 bits sizeof(short) is at least 16 bits sizeof(int) is at least 16 bits sizeof(long) is at least 32 bits and, in C99, sizeof(long long) is at least 64 bits 3-4 1.3 In C99, the new <inttypes.h> header provides Standard names for exact-size types: int16_t, uint32_t, etc. 4 1.4 In C99, long long is defined as an integer type with, in effect, at least 64 bits. 6 1.7 There may be zero definitions of an external function or variable that is not referenced in any expression. [Thanks and $1 to James Stern] 7 1.7 "use include to bring" should be "use #include to bring" 11 1.14 In the second fix, at the bottom of the page, it could conceivably be necessary to precede http://www.eskimo.com/~scs/C-faq/book/Errata.html (1 of 10) [26/03/2003 11:40:03 p.m.] C Programming FAQs Errata the line typedef struct node *NODEPTR; with the line struct node; for the reason mentioned on page 13, although in that case one of the two other fixes would clearly be preferable. [Thanks to James Stern] 13 1.15 In the alternate fix, at the bottom of the page, it could conceivably be necessary to precede the typedef declarations with the lines struct a; struct b; although again, putting those typedefs after the complete structure definitions would clearly be preferable in that case.