Expert C Programming errata // last update: Jul 26 1999 NON-TRIVIAL ERRATA: p.52 use "file -h * | grep link" to see symbolic links in SVr4 p.245: In the last example (Pointer Alternative 3) add R5 + R2 into R2 store R2 into [R0] All 3 occurences of "R2" should be "R1" in these 2 lines. p.253 typedef char vegetable[10]; vegetable carrot[20]; should be: typedef char vegetable[20]; vegetable carrot[10]; p.283 The include of should be ERRATA/ADDITIONS/CLARIFICATION p.iii change e-mail address to pvdl@afu.com drop the apostrophe from "Typo's" p.xiv missing ";" after "int bar" p.xxii point out that the warning not to remove the "tuna fish" comment is only in Sun manpages from SunOS 4.1.1 on. The tuna fish comment itself is in most of BSD manpage sets. p.xxv "daylight savings time" s.b. "daylight saving time" p.4 "mov (r0)+,(r1)+" s.b. "movb (r0)+,(r1)+" p.9 last para., sentence 2 missing closing ) at very end. p.10 add the date 1983 above the Ada box in fig 1.2 p.12 remove second comma in "In 1983, a C working group," p.13 "ISO/IEC 9899-1990" s.b. "ISO/IEC 9899:1994" i.e. the standard has a ":" not a "-" and was updated in 1994. p.18 "The ANSI C standard's section 4" s.b. "section 7" p.19 Two different spellings of "UniForum" are used. p.21 make strcpy return type be "char *" not "int". p.22 midpage, delete surplus "the" from "the all the" p.23 midpage, "cp = cpp; /* results..." has "an" instead of "a" p.24 Insert "a" into "The keyword const doesn't turn a variable into [] constant" p.24 insert "from" into "the value [] being modified" p.26 last two para's, two places, "the result" s.b. "the resulting type promotion" p.29 Whoops, GNU is not aiming at public domain, but a free software. p.30 call "pragma" a directive, not a keyword p.31 footnote 1, change to read "The most definitive account, from Fred Webb who worked at NASA at the time and saw the actual source code, can be seen..." p.36 say "most lints don't catch this" -- the SCO Unix one does see it as an unreferenced label. p.37 confusion over "default" with the English meaning and the C meaning! change "default fall-through" to "fall-through" (3 places on the page) p.40 line 2, s.b. "compile-time" p.42 remove ";" after "()" on the functions in code box. remove the three occurrences of the word ``function'' (in box) p.42,43 Technically, C does not have global scope, and uses the term "external linkage" instead. It would be a good idea to explain here what linkage is (global scope). p.44 say "sizeof's type needs to be enclosed in parentheses", not "brackets." p.49 change the sentence starting "If the stack..." to "Most architectures are vulnerable to overwriting an existing entry in the middle of the stack with something bigger, that also overwrites neighboring entries. The cost of checking each stack access for size and permission would be prohibitive in software" p.67 Both tables would benefit from having their overall topic in bold at the top, rather than only in italics at the bottom. p.67 add optional "= initial_value" after ", declarator" at the end. p.69 In the second code box, the ; is missing after yy in struct date_tag { short dd,mm,yy } my_birthday, xmas; p.70 Missing ";" after "_lb" in the top two code boxes. Should be: struct veg { int weight, price_per_lb; }; and struct veg { int weight, price_per_lb; } onion, radish, turnip; p.81 missing ";" after the second foo in the heading starting "What " p.81 missing ";" after the second baz in the second code box: p.81 "baz baz" is illegal p.81 Say that the name spaces of field names of different structures are also disjoint. Even though this was true for most compilers before the official introduction of ANSI C, it was not the case for most older compilers. For that reason, in the UNIX 4.2 BSD kernel code the field names are prefixed with an initial that alludes to the struct tag: struct veggies_tag { int v_tomato; char v_squash[4]; float v_carrot; } ; p.82 box: missing ";" after "price_per_lb", both lines p.83 Also use typedefs to provide a simple name subsequently used in a cast. e.g. typedef int (* ptr-to-int-fun)(void); char * p; ... x = (ptr-to-int-fun) p; "Figure 3.4" should say "Figure 3.3" p.87 It wasn't Silicon Graphics -- it was Cygnus Support in Mtn View p.88 line 4, we use atoi() later, so should #include here POP and PUSH are macros, so could use upper case throughout. p.89 function gettoken(): - comment says "1-9"; should be 0-9. - the function won't handle identifiers with underscores. p.101 Change title to "Define as Pointer/Reference as Array" p.103 mango allocates 100 ints, not 100 characters. p.113 point out that, even with static linking, the whole of libc.a is not brought into the executable, just the routines needed. Adjust the diagram to make this clear. p.114 line 17, "upgrades" -> "well-behaved upgrades" p.117 Be consistent about using "PICode", (also used "PIcode" and on the next page, "PI code".) p.119 /usr/ccs/libcurses.a should be /usr/ccs/lib/libcurses.a p.123 change "(perhaps less convenient manner)" to "(perhaps less convenient) manner" say "don't actually call the function" p.138 say "hard" instead of "harder" p.139 change the 3 occurrences of "Bill Joy" to "Kirk McKusick" Bill did the design, Kirk the coding, and it's Kirk's b'day. p.139 ELF files start with "\x7F" not "F" p.140 There should be #include for malloc() p.145 replace "(It will be overwritten by the next function call)" by "(When this function returns to its caller, the memory will be overwritten by the next function call)." p.146 for total portability use printf("The stack... %p\n", &i); not "%#x" and add "#include " and "return 0" p.147 Add info: While discussing the frame pointer for a Sparc, the register fp is pointed out in the text. The Intel equivalent is the BP register, standing for base pointer (not to be confused with SS for Stack Segment, and SP for Stack Pointer). p.150 In the two center code examples in boxes at the left hand side of the page, the code erroneously reads "i>o" ("eye greater than oh") instead of "i>0" ("eye greater than zero"). "a" in "a called by main" is in the wrong font. p.150 In the third dashed box in fig 6.5, line 5 should be in bold ("printf") and lines 2 and 3 should be plain. p.153 "The contents of the j are destroyed when it is used in a longjmp()." replace by: "after use in a longjmp(), the contents of ``jmp_buf j'' are no longer valid because that stack frame has been destroyed" p.153,4 The code box at foot and head of pages (resp.) repeats the #include It only needs one (tho' two won't cause an error). p.154 warn readers that the only reliable way to ensure that a local variable retains the value it had at the time of the longjmp is to declare it volatile. (this is for variables whose value changes between the execution of setjmp, and the return via longjmp.) p.156 (top) delete "In this case". p.157 delete the line on cstyle -- this is a script internal to Sun. p.158 "Did the transmission go OK?": unclosed quoted string p.161 "ifconfig -a" is a better way to determine ether and IP. p.161 The Princeton programming competition was actually at CMU and was not quite as dramatic as shown here (time didn't run backwards) This is the story as it was told to me. Of course, stories get dramatized as they are passed on, and I'm told that it wasn't quite such a mondo yuck-fest. p.162 "Maradonna" should be "Maradona" p.167 "Two 16-bit bytes" s.b. "Two 16-bit words" p.169 s.b. Seattle Computer Products' p.172 transpose "memory" and "display" in the description of segment B0000 p.172 England is now moving over to billion = "1000 million" p.172 there is a repeated parenthesis. It reads "(10^18))" p.173 Missing memory model. I believe it was Borland to provided the nomenclature for the missing memory model in the table (which, correctly labels the source as Microsoft C). The "tiny" memory model represents a single 64K segment that has both the STACK and TEXT in it. (The CS, DS, ES, and SS segments were all equal.) This was to support the .COM files, which were quickly replaced by .EXE files. p.174 say in the first paragraph that practically all computer systems from the largest to the very smallest (except PCs and PDAs) use virtual memory now. p.174 'regions of memory lay' should be 'regions of memory lie'. p.181 a seven-fold increase is actually just a 600% improvement or just say it runs several times faster p.183 add a "," after "Whenever you write malloc" p.188-9 if the memory is referenced through the uninitialized pointer any of the two exceptions may occur. If the value in the pointer is properly aligned it will cause the Segmentation Fault just as described. If it is by chance unaligned it may cause the Bus Error even if the address is invalid. p.189 need a semi-colon after "int i" p.190 The sentence ending "cause of the fault" needs a period at end. p.199 the program using SIGINT might not work as described. The problem is that the signal may occur while the first printf is executing. As Plauger notes in his section on signal handling in "The Standard C Library" if the async sinal occurs during the first printf, and the signal handler does a printf, then a confused state may occur. Second, the printf may call malloc (at least some printf's do this). This would cause problems if the interrupt occurs during the malloc call. Fix by putting "return 0;" after printf("back in main"); There is a specific prohibition in 7.7.1.1 (discussing signal handlers) which says: If the signal occurs other than as a result of calling the abort or raise function, the behavior is undefined if the signal handler calls any function in the standard library other than the signal function itself [...] p.202 "Summer 1959" s.b. "June 1957" p.205 replace "The automatic promo ... before sizeof sees it" with: "Character literals have type int, and they get there by following the rules for promotion from type char. p.209 "confuse maintenance programmers" should end with period. p.211 last para. ..function declaration.. should be function definition. p.213 change that kbhit paragraph (right before the Handy Heuristic) to say: "People often wonder why ANSI C didn't define a standard function to get a character if a key has been pressed. Without a standard function, every system has a different method and program portability is lost. The argument against providing kbhit() as part of the standard is that some OS's will find it difficult to provide, and there are many other terminal I/O features that are not standardized. The argument for providing it is that it is very useful for many interactive programs, including editors, games, and other software some of which don't need the myriad of other terminal I/O features that could be standardized. p.223 "in brackets before the" s.b. "in parentheses before the". p.228 EBCIDIC should be EBCDIC p.231 "#define U(y,z)while(p=..." needs a space before "while" p.233 the array crlf should have a third, 0, element to terminate the string. p.234 There should be #include for atoi() p.245 "The italics" s.b. "the diagram", as there are no italics p.246 second sentence after the first box says: ``In the specific ... formal function argument ...''. change to "formal function parameter" for consistency. p.248 In Ada, element size isn't carried around at runtime. p.252 fig 9-5 change "ADA" to "Ada" p.261 "%#x" is used to print pointer values, "%p" is more portable. Also add #include p.263 Add "." at end of last sentence on page. p 264, in figure 10-2, there ought to be 6 slots, not 5, in each of the pea[i]'s p.265 "char * pea[5]" s.b. "char *pea[4]" for consistency with f10.3 p.265 "Illiffe" should be "Iliffe" throughout ch 10. p.266 if you make the change to p[4], the loop s.b. "for (j=0;j<4;j++)" and omit the opening brace after the "for ( ... ) " p.269 under the diagram the right closing bracket should be unbolded in "char * p[4]". p.274 "highest element array[x+1]" should be "highest element of array[x+1]" p.278 should be either "malloc" or calloc( 20, sizeof(int) ); p.298: "C++ also provides automatic ... cleanup when data goes out of scope ..." A destructor executes at the end of an object's lifetime (extent), not when it goes out of scope. Sometimes the two are the same, but not in general. E.g. a static variable in a function. p.304 main() is missing a return. That's not C++. [Though it may become C++. There was such a proposal.] p.305 %x is used to format a pointer. Could use %p p.309 alang@trashbin.MV.COM (Alan Groupe) reports that he already invented candy-grapes, so I sent him the $1 bounty for his ready wit -- he seems to have the sort of initiative that should be encouraged. p.310 in Software Dogma, second fragment (class Apple) is missing ";" after terminating "}" p.315 at the foot of the page, make clear that the signature has to be *identical* for virtual functions, and it must *not* be identical for mere overloading (so you can tell which was reqd from the args). Overloading is resolved at compiletime, polymorphism at runtime. p.325 Change "Windows NT is about 4M lines of C++", to "the graphics part of windows NT (which was later, slower, and bigger than expected) was written in C++" p.325 Put a period at the end of the sentence ending "has been compromised". p.326 Name mangling was introduced with cfront v2.0 and by now, all ANSI C++ compilers do name mangling, regardless of whether they produce C code or assembly code. This is a portable way of doing type checking, but unfortunately it implies that all your C++ files need to be compiled with the *same* C++ compiler (because the name mangling scheme may differ among compilers). This is a big defect in the C++ reuse model, since it effectively prevents reuse at the binary level. p.336 Right before "Once," say "So you also might use this in a macro." p.335 start off the pointers at element 1 and 2 (not 3). p.338 "Plaugher" should be "Plauger" p.338 s.b. a space between "inTable" p.340 "create()" s.b. "creat()" p.340 Try to use APL font for the APL example, and it looks like slightly bogus code (still makes the point though). p.342 O(N) means *at most* linearly. Something that is O(N) is also O(N^2), but not vice versa. p.342 Discussion of the two-capacitor problem describes the ideal circuit as having no inductance. The real problem is that the circuit has no resistance; heat/energy is dissipated in the IR losses. As the resistance goes to zero, the current would become infinite, producing the discontinuity. p.342 "interpolate" s.b. "extrapolate", as you're going from a sample to a larger set. p.346 re the Gravitational Method II "...if there was any practical way..." There is, and such a device has been a standard tool for petroleum geophysicists for over twenty years. The Lacoste Romberg gravimeter is about the size of a toaster, needs no power except for a light to read the scale. Built out of invar and fused quartz, you adjust a (zero relaxed length) spring to null out the gravity force. I used one in a class demo to measure the height of the lecture hall table. In a few minutes I got it to within two inches. p.352 Add ref to Ritchie to page 46 --------------- German edition errata sheet has these entries: last update Apr 28 1999 p.241 The comment under "Datei 2" confuses "ohne" with "mit", a typing error destroying the meaning of the context. p.257 - replace the "t" within "ist" (as a translation result) by a blank in code line # 6, - the next line has to be given a backslash at the end of line - the last line but two, replace "!!" by "||" - the last line, replace "isalum" by "isalnum". - right parenthesis is missing at the end of the penultimate line - last line, remove unneeded right paren. - note that final program fails on, e.g. "unsigned char c;" --- Thanks to the following people for reporting these items: Dave Woolaway, John Hevelin, Charles Lin, Subu Rama, Christian Kirsch, Dave Shroder, Theodore Reed, Mike Sullivan Paul Wildes, Karin Ellison, Steve Johnston, Steve Teitelbaum C. Tondo, Lennart Brändström, Bill Imlah, Gary Pecor Tony Fitzgerald, Michael Hamilton, Joe Ferguson, Dave Mason Jan de Ruiter, Tom Neary, Peter M. Vince, Steve Gallagher Adam Fields, Dan Pop, Tommy Lennhamn, Prof. Donald Knuth Rob Tresader, John F. Dumas, Greg Black, Howard Gantz Rafal Kowalski, Fred Webb, George A. McCaskill Neil Menzies, Mal Haysom, Ajit Panakal, Bob Collins, Cary Jamison, Troy De Jongh, Bill Piper, James F. Garrigues, Fazl Rahman, Walter B. Paul, Adrian Bottoms, Hartmut Hoss Alan Groupe, Dan Lyttle, Anthon Pang, William J. Evans, Wilhelm Mueller, Johanes Suhardjo, Ben Arbogasta, James Scott Noah Friedman, Mark Harig, Peter Seebach, David Wall Matthias Froehlich, Jeffrey C. Chen, M C Dorrington, Steve Protopapas, Richard Hendricks, Walt Stoneburner, Chin Fang, Juha Niskanen