📄 errata.html
字号:
<!-- Mirrored from c-faq.com/book/Errata.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:58 GMT --><head><title>C Programming FAQs Errata</title></head><body><pre>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 beobtained at any time by anonymous ftp from ftp.eskimo.comin the file ~scs/C-faq/book/Errata, or on the web athttp://www.eskimo.com/~scs/C-faq/book/Errata.html .(If you read this years from now and those addresses don'twork, try ftp://ftp.aw.com/cseng/authors/summit/cfaq/ orhttp://www.awl.com/cseng/titles/0-201-84519-9 .)scs 2002-Oct-26page 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 bits3-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 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. [Thanks to James Stern]18 1.22 The odd "return 0;" line is not really necessary.20 1.24 Another possible arrangement is /* file1.h */ #define ARRAYSZ 3 extern int array[ARRAYSZ]; /* file1.c */ #include "file1.h" int array[ARRAYSZ]; /* file2.c" #include "file1.h" [Thanks to Jon Jagger]23 1.29 [2nd bullet] "everything else termed" should be "everything else, termed"24 1.29 [Rule 3] "if the header" should be "if any header". [Thanks and $1 to James Stern]24 1.29 [Rule 4] "(i.e., function names)" should be "(e.g., function names)". [Thanks and $1 to James Stern]24 1.29 The text at the bottom of the page suggests that "future directions" name patterns such as str[a-z]* are reserved only if their corresponding headers (e.g. <stdlib.h>) are included. The reserved function names are unconditionally reserved; it is only the macro names that are reserved only if the header is included. [Thanks and $1 to Mark Brader]25 1.29 "if you don't include the header files" should be "if you don't include any header files".32 2.4 Besides -> and sizeof, the . operator, as well as declarations of actual structures, also require the compiler to know more about the structure and so preclude incomplete or hidden definitions. [Thanks to James Stern]33-36 2.6 In C99, a structure can contain a variable-length array (VLA) as its last member, providing a well-defined, Standard-compliant alternative.38 2.10 C99 *does* have a way of generating anonymous structure values: "compound literals".40 2.12 When trying to minimize wasted space in structures, array members should be ordered based on the size of their primitive types, not their overall size. [Thanks and $1 to James Stern]43 2.20 "ANSI/SIO" should be "ANSI/ISO" In C99, the "designated initializer" mechanism allows any member of a union to be initialized.50 3.3 Of course, another way to increment i is i += 1. [Thanks to James Stern]51 3.4 "higher precedence than *):" should be "higher precedence than *:"52 3.6 Delete the close parenthesis at the end of the answer.57 3.12 In C++, the prefix form ++i is preferred. [Thanks to James Stern]68 4.5 The reference to ANSI Sec. 3.3.4 should say "esp. footnote 44". [Thanks to Willis Gooch]72-3 4.10 In C99, it is possible to use a "compound literal" to generate a pointer to an (unnamed) constant value.73 4.11 The reference to K&R2 sec. 5.2 should be pp. 95-7. [Thanks and $1 to Nikos Triantafillis]75 4.13 "can interconverted" should be "can be interconverted". [Thanks and $1 to Howard Ham]84 5.8 Either the comma or the parentheses in the answer should be changed.95 6.2 The typography in the following line is inconsistent for the "x" of "x[3]".104-5 6.15 C99 introduces variable-length arrays (VLA's) which, among other things, *do* allow declaration of a local array of size matching a passed-in array.105-7 6.16 In C99, another solution is to use a variable-length array.110 6.19 C99's variable-length arrays are also a nice solution to this problem.115 7.1 The close parenthesis and period ")." at the bottom of the page are not part of the #define line.121 7.9 There is an extra semicolon at the end of the first line of mymalloc's definition. [Thanks and $1 to Todd Burruss]126 7.10 Missing "it"; should be "even if it is not dereferenced". [Thanks and $1 to Clinton Sheppard]132 7.30 It would be even safer to add a second test on nchmax: if(nchread >= nchmax) { nchmax += 20; if(nchread >= nchmax) { free(retbuf); return NULL; } newbuf = realloc(retbuf, nchmax + 1); The concern is that, while reading a *very* long line, nchmax might overflow, wrapping back around to 0. [Thanks to Mark Brader]134 7.32 C99's variable-length arrays (VLA's) can be used to more cleanly accomplish most of the tasks which alloca used to be put to.136 8.1 "Although string literal" should be "Although a string literal"136 8.2 C can be tricked into seeming to assign an array as a whole if you hide the array inside a structure or union. [Thanks and $1 to James Stern]143 9.2 The example variable isvegetable should perhaps be named is_vegetable to avoid naming conflicts (see question 1.29). [Thanks and $1 to Jon Jagger]151 10.4 Extra space in "/* (no trailing ; ) */".152 10.6 [paragraph below bullets] "bring the header wherever" should be "bring the header in wherever"158 10.15 If you have to, you can obviously #define a companion macro name for each typedef, and use #ifdef with that. [Thanks to James Stern]161 10.21 The suggested replacement macro should parenthesize c: #define CTRL(c) ((c) & 037) [Thanks and $1 to James Stern]163-4 10.29 C99 introduces formal support for macros with variable numbers of arguments.164-5 10.27 The file parameter of the dbginfo() function and the fmt parameter of the debug() function could be of type const char *. [Thanks to James Stern]168 11.1 The story has gotten longer: A new revision of the C Standard, "C99", has been ratified, superseding the original ANSI C Standard. This Errata list has been updated to note those answers in the book which have become dated due to C99 changes.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -