home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / C-faq / diff < prev    next >
Internet Message Format  |  1999-03-02  |  89KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news.kodak.com!news-nysernet-16.sprintlink.net!news-east1.sprintlink.net!-program!news-peer1.sprintlink.net!news-backup-west.sprintlink.net!news.sprintlink.net!news.eskimo.com!scs
  2. From: scs@eskimo.com (Steve Summit)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,alt.comp.lang.learn.c-c++,comp.answers,alt.answers,news.answers
  4. Subject: comp.lang.c Changes to Answers to Frequently Asked Questions (FAQ)
  5. Followup-To: poster
  6. Date: 1 Mar 1999 18:54:42 GMT
  7. Organization: better late than never
  8. Lines: 2131
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <1999Mar01.1047.scs.0006@eskimo.com>
  11. Reply-To: scs@eskimo.com
  12. NNTP-Posting-Host: eskimo.com
  13. X-Archive-name: C-faq/diff
  14. X-URL: http://www.eskimo.com/~scs/C-faq/top.html
  15. X-PGP-Signature: Version: 2.6.2
  16.     iQCSAwUBNtrhad6sm4I1rmP1AQGwKgPmOpt99HTtWp9fU2cwb/icG762Nm/6h6P3
  17.     2doEHyZ/Vm8Na0CPxB4qUkhDgScKQ5YOprF18hfbBMKSbMBnulXQRyr+qXQiw7PI
  18.     s3+QDLi1FEWj8Kbuea/24YivE1eD+hF7Du7ofslSx9N7oily4Nsoe9sZF+IH5p/Q
  19.     8RMSMRk=
  20.     =cIsT
  21. Originator: scs@eskimo.com
  22. Xref: senator-bedfellow.mit.edu comp.lang.c:347258 comp.lang.c.moderated:11623 alt.comp.lang.learn.c-c++:12872 comp.answers:35268 alt.answers:40291 news.answers:152571
  23.  
  24. Archive-name: C-faq/diff
  25. Comp-lang-c-archive-name: C-FAQ-list.diff
  26. URL: http://www.eskimo.com/~scs/C-faq/top.html
  27.  
  28. This article is a repost of the differences between the previous
  29. version of the comp.lang.c FAQ list (version 3.4, last modified
  30. September 5, 1996, last posted January 1, 1999) and the current
  31. one (version 3.4, first posted February 7, 1999).  These diffs
  32. have been heavily edited, for readability's sake, and are not
  33. suitable as input to a patch program.
  34.  
  35. I must beg a number of peoples' pardons by confessing that, once
  36. again, I have not managed to acknowledge all of the suggestions
  37. in the current pile.  Apologies to those of you who have still
  38. not heard from me or seen your suggestion used here, even after
  39. many months.
  40.  
  41. Note also that, as of this writing, these changes have *not*
  42. yet been incorporated into the HTML version of the FAQ list at
  43. http://www.eskimo.com/~scs/C-faq/top.html .
  44.  
  45. (For those not familiar with "diff" notation, in the lines that
  46. follow, a '<' character indicates old, changed, or deleted text,
  47. and a '>' character indicates new text.)
  48.  
  49. First, the new entries:
  50.  
  51. ==========
  52. > 3.3b:    Here's a slick expression:
  53. >
  54. >        a ^= b ^= a ^= b
  55. >
  56. >    It swaps a and b without using a temporary.
  57. >
  58. > A:    Not portably, it doesn't.  It attempts to modify the variable a
  59. >    twice between sequence points, so its behavior is undefined.
  60. >
  61. >    For example, it has been reported that when given the code
  62. >
  63. >        int a = 123, b = 7654;
  64. >        a ^= b ^= a ^= b;
  65. >
  66. >    the SCO Optimizing C compiler (icc) sets b to 123 and a to 0.
  67. >
  68. >    See also questions 3.1, 3.8, 10.3, and 20.15c.
  69. ==========
  70. > 7.3b:    I just tried the code
  71. >
  72. >        char *p;
  73. >        strcpy(p, "abc");
  74. >
  75. >    and it worked.  How?  Why didn't it crash?
  76. >
  77. > A:    You got lucky, I guess.  The memory pointed to by the
  78. >    unitialized pointer p happened to be writable by you,
  79. >    and apparently was not already in use for anything vital.
  80. ==========
  81. > 7.3c:    How much memory does a pointer variable allocate?
  82. >
  83. > A:    That's a pretty misleading question.  When you declare
  84. >    a pointer variable, as in
  85. >
  86. >        char *p;
  87. >
  88. >    you (or, more properly, the compiler) have allocated only enough
  89. >    memory to hold the pointer itself; that is, in this case you
  90. >    have allocated sizeof(char *) bytes of memory.  But you have
  91. >    not yet allocated *any* memory for the pointer to point to.
  92. >    See also questions 7.1 and 7.2.
  93. ==========
  94. > 11.12a: What's the correct declaration of main()?
  95. >
  96. > A:    Either int main(), int main(void), or int main(int argc,
  97. >    char *argv[]) (with alternate spellings of argc and *argv[]
  98. >    obviously allowed).  See also questions 11.12b to 11.15 below.
  99. >
  100. >    References: ISO Sec. 5.1.2.2.1, Sec. G.5.1; H&S Sec. 20.1 p.
  101. >    416; CT&P Sec. 3.10 pp. 50-51.
  102. ==========
  103. > 12.9b:  What printf format should I use for a typedef like size_t
  104. >    when I don't know whether it's long or some other type?
  105. >
  106. > A:    Use a cast to convert the value to a known, conservatively-
  107. >    sized type, then use the printf format matching that type.
  108. >    For example, to print the size of a type, you might use
  109. >
  110. >        printf("%lu", (unsigned long)sizeof(thetype));
  111. ==========
  112. > 12.36b: How can I arrange to have output go two places at once,
  113. >    e.g. to the screen and to a file?
  114. >
  115. > A:    You can't do this directly, but you could write your
  116. >    own printf variant which printed everything twice.
  117. >    See question 15.5.
  118. ==========
  119. > 13.14b: Does C have any Year 2000 problems?
  120. >
  121. > A:    No, although poorly-written C programs do.
  122. >
  123. >    The tm_year field of struct tm holds the value of the year minus
  124. >    1900; this field will therefore contain the value 100 for the
  125. >    year 2000.  Code that uses tm_year correctly (by adding or
  126. >    subtracting 1900 when converting to or from human-readable
  127. >    4-digit year representations) will have no problems at the turn
  128. >    of the millennium.  Any code that uses tm_year incorrectly,
  129. >    however, such as by using it directly as a human-readable
  130. >    2-digit year, or setting it from a 4-digit year with code like
  131. >
  132. >        tm.tm_year = yyyy % 100;    /* WRONG */
  133. >
  134. >    or printing it as an allegedly human-readable 4-digit year with
  135. >    code like
  136. >
  137. >        printf("19%d", tm.tm_year);    /* WRONG */
  138. >
  139. >    will have grave y2k problems indeed.  See also question 20.32.
  140. >
  141. >    References: K&R2 Sec. B10 p. 255; ISO Sec. 7.12.1; H&S Sec. 18.4
  142. >    p. 401.
  143. ==========
  144. > 18.13b: Is there an on-line C reference manual?
  145. >
  146. > A:    Two possibilities are
  147. >    http://www.cs.man.ac.uk/standard_c/_index.html and
  148. >    http://www.dinkumware.com/htm_cl/index.html .
  149. ==========
  150. > 18.15d: I need code for performing multiple precision arithmetic.
  151. >
  152. > A:    Some popular packages are the "quad" functions within the BSD
  153. >    Unix libc sources (ftp.uu.net, /systems/unix/bsd-sources/..../
  154. >    /src/lib/libc/quad/*), the GNU MP library, the MIRACL package
  155. >    (see http://indigo.ie/~mscott/ ), and the old Unix libmp.a.
  156. >    See also questions 14.12 and 18.16.
  157. >
  158. >    References: Schumacher, ed., _Software Solutions in C_ Sec. 17
  159. >    pp. 343-454.
  160. ==========
  161. > 19.16b: How do I copy files?
  162. >
  163. > A:    Either use system() to invoke your operating system's copy
  164. >    utility (see question 19.27), or open the source and destination
  165. >    files (using fopen() or some lower-level file-opening system call),
  166. >    read characters or blocks of characters from the source file,
  167. >    and write them to the destination file.
  168. >
  169. >    References: K&R Sec. 1, Sec. 7.
  170. ==========
  171. > 19.40c: I'm trying to compile this program, but the compiler is
  172. >    complaining that "union REGS" is undefined, and the linker
  173. >    is complaining that int86() is undefined.
  174. >
  175. > A:    Those have to do with MS-DOS interrupt programming.  They don't
  176. >    exist on other systems.
  177. ==========
  178. > 20.15b: People claim that optimizing compilers are good and that we no
  179. >    longer have to write things in assembler for speed, but my
  180. >    compiler can't even replace i/=2 with a shift.
  181. >
  182. > A:    Was i signed or unsigned?  If it was signed, a shift is not
  183. >    equivalent (hint: think about the result if i is negative and
  184. >    odd), so the compiler was correct not to use it.
  185. ==========
  186. > 20.15c: How can I swap two values without using a temporary?
  187. >
  188. > A:    The standard hoary old assembly language programmer's trick is:
  189. >
  190. >        a ^= b;
  191. >        b ^= a;
  192. >        a ^= b;
  193. >
  194. >    But this sort of code has little place in modern, HLL
  195. >    programming.  Temporary variables are essentially free,
  196. >    and the idiomatic code using three assignments, namely
  197. >
  198. >        int t = a;
  199. >        a = b;
  200. >        b = t;
  201. >
  202. >    is not only clearer to the human reader, it is more likely to be
  203. >    recognized by the compiler and turned into the most-efficient
  204. >    code (e.g. using a swap instruction, if available).  The latter
  205. >    code is obviously also amenable to use with pointers and
  206. >    floating-point values, unlike the XOR trick.  See also questions
  207. >    3.3b and 10.3.
  208. ==========
  209. > 20.20b: Is C a great language, or what?  Where else could you write
  210. >    something like a+++++b ?
  211. >
  212. > A:    Well, you can't meaningfully write it in C, either.
  213. >    The rule for lexical analysis is that at each point during a
  214. >    straightforward left-to-right scan, the longest possible token
  215. >    is determined, without regard to whether the resulting sequence
  216. >    of tokens makes sense.  The fragment in the question is
  217. >    therefore interpreted as
  218. >
  219. >        a ++ ++ + b
  220. >
  221. >    and cannot be parsed as a valid expression.
  222. >
  223. >    References: K&R1 Sec. A2 p. 179; K&R2 Sec. A2.1 p. 192; ISO
  224. >    Sec. 6.1; H&S Sec. 2.3 pp. 19-20.
  225. ==========
  226. > 20.24b: What is assert() and when would I use it?
  227. >
  228. > A:    It is a macro, defined in <assert.h>, for testing "assertions".
  229. >    An assertion essentially documents an assumption being made by
  230. >    the programmer, an assumption which, if violated, would indicate
  231. >    a serious programming error.  For example, a function which was
  232. >    supposed to be called with a non-null pointer could write
  233. >
  234. >        assert(p != NULL);
  235. >
  236. >    A failed assertion terminates the program.  Assertions should
  237. >    *not* be used to catch expected errors, such as malloc() or
  238. >    fopen() failures.
  239. >
  240. >    References: K&R2 Sec. B6 pp. 253-4; ISO Sec. 7.2; H&S Sec. 19.1
  241. >    p. 406.
  242. ==========
  243. > 20.39b: What do "lvalue" and "rvalue" mean?
  244. >
  245. > A:    Simply speaking, an "lvalue" is an expression that could appear
  246. >    on the left-hand sign of an assignment; you can also think of it
  247. >    as denoting an object that has a location.  (But see question
  248. >    6.7 concerning arrays.)  An "rvalue" is any expression that has
  249. >    a value (and that can therefore appear on the right-hand sign of
  250. >    an assignment).
  251. ==========
  252.  
  253.  
  254. Next, the significant changes:
  255.  
  256. ==========
  257. < 1.4:    What should the 64-bit type on new, 64-bit machines be?
  258. <
  259. < A:    Some vendors of C products for 64-bit machines support 64-bit
  260. <    long ints.  Others fear that too much existing code is written
  261. <    to assume that ints and longs are the same size, or that one or
  262. <    the other of them is exactly 32 bits, and introduce a new,
  263. <    nonstandard, 64-bit long long (or __longlong) type instead.
  264. <
  265. <    Programmers interested in writing portable code should therefore
  266. <    insulate their 64-bit type needs behind appropriate typedefs.
  267. <    Vendors who feel compelled to introduce a new, longer integral
  268. <    type should advertise it as being "at least 64 bits" (which is
  269. <    truly new, a type traditional C does not have), and not "exactly
  270. <    64 bits."
  271. <
  272. <    References: ANSI Sec. F.5.6; ISO Sec. G.5.6.
  273. ---
  274. > 1.4:    What should the 64-bit type on a machine that can support it?
  275. >
  276. > A:    The forthcoming revision to the C Standard (C9X) specifies type
  277. >    long long as effectively being at least 64 bits, and this type
  278. >    has been implemented by a number of compilers for some time.
  279. >    (Others have implemented extensions such as __longlong.)
  280. >    On the other hand, there's no theoretical reason why a compiler
  281. >    couldn't implement type short int as 16, int as 32, and long int
  282. >    as 64 bits, and some compilers do indeed choose this
  283. >    arrangement.
  284. >
  285. >    See also question 18.15d.
  286. >
  287. >    References: C9X Sec. 5.2.4.2.1, Sec. 6.1.2.5.
  288. ==========
  289.   A:    This technique is popular, although Dennis Ritchie has called it
  290.     "unwarranted chumminess with the C implementation."  An official
  291.     interpretation has deemed that it is not strictly conforming
  292. <    with the C Standard.  (A thorough treatment of the arguments
  293. <    surrounding the legality of the technique is beyond the scope of
  294. <    this list.)  It does seem to be portable to all known
  295. ---
  296. >    with the C Standard, although it does seem to work under all
  297.     known implementations.
  298. ==========
  299. >    C9X will introduce the concept of a "flexible array member",
  300. >    which will allow the size of an array to be omitted if it is
  301. >    the last member in a structure, thus providing a well-defined
  302. >    solution.
  303. >
  304. >    References: Rationale Sec. 3.5.4.2; C9X Sec. 6.5.2.1.
  305. ==========
  306. < A:    C has no way of generating anonymous structure values.  You will
  307. ---
  308. > A:    As of this writing, C has no way of generating anonymous
  309. >    structure values.  You will have to use a temporary structure
  310.     variable or a little structure-building function.
  311. ==========
  312. <    building function.  (gcc provides structure constants as an
  313. <    extension, and the mechanism will probably be added to a future
  314. <    revision of the C Standard.)  See also question 4.10.
  315. ---
  316. >    The C9X Standard will introduce "compound literals"; one form of
  317. >    compound literal will allow structure constants.  For example,
  318. >    to pass a constant coordinate pair to a plotpoint() function
  319. >    which expects a struct point, you will be able to call
  320. >
  321. >        plotpoint((struct point){1, 2});
  322. >
  323. >    Combined with "designated initializers" (another C9X feature),
  324. >    it will also be possible to specify member values by name:
  325. >
  326. >        plotpoint((struct point){.x=1, .y=2});
  327. >
  328. >    See also question 4.10.
  329. >
  330. >    References: C9X Sec. 6.3.2.5, Sec. 6.5.8.
  331. ==========
  332. < A:    ANSI Standard C allows an initializer for the first-named member
  333. <    of a union.  There is no standard way of initializing any other
  334. <    member (nor, under a pre-ANSI compiler, is there generally any
  335. <    way of initializing a union at all).
  336. ---
  337. > A:    The current C Standard allows an initializer for the first-named
  338. >    member of a union.  C9X will introduce "designated initializers"
  339. >    which can be used to initialize any member.
  340. ==========
  341. 3.5:    But what about the && and || operators?
  342.     I see code like "while((c = getchar()) != EOF && c != '\n')" ...
  343.  
  344. < A:    There is a special exception for those operators (as well as the
  345. <    ?: and comma operators): left-to-right evaluation is guaranteed
  346. <    (as is an intermediate sequence point, see question 3.8).  Any
  347. <    book on C should make this clear.
  348. ---
  349. > A:    There is a special "short-circuiting" exception for those
  350. >    operators.  The right-hand side is not evaluated if the left-
  351. >    hand side determines the outcome (i.e. is true for || or false
  352. >    for &&).  Therefore, left-to-right evaluation is guaranteed, as
  353. >    it also is for the comma operator.  Furthermore, all of these
  354. >    operators (along with ?:) introduce an extra internal sequence
  355. >    point (see question 3.8).
  356. ==========
  357.   4.8:    I have a function which accepts, and is supposed to initialize,
  358.     a pointer:
  359.  
  360. <        void f(ip)
  361. <        int *ip;
  362. ---
  363. >        void f(int *ip)
  364.         {
  365. ==========
  366. <    also question 15.3.)  It is safest to properly cast all null
  367. <    pointer constants in function calls: to guard against varargs
  368. <    functions or those without prototypes, to allow interim use of
  369. <    non-ANSI compilers, and to demonstrate that you know what you
  370. <    are doing.  (Incidentally, it's also a simpler rule to
  371. <    remember.)
  372. ---
  373. >    also question 15.3.)  It is probably safest to properly cast
  374. >    all null pointer constants in function calls, to guard against
  375. >    varargs functions or those without prototypes.
  376. ==========
  377. < A:    Follow these two simple rules:
  378. ---
  379. > A:    Here are two simple rules you can follow:
  380. ==========
  381.     The rest of the discussion has to do with other people's
  382.     misunderstandings, with the internal representation of null
  383. <    pointers (which you shouldn't need to know), and with ANSI C
  384. <    refinements.  Understand questions 5.1, 5.2, and 5.4, and
  385. ---
  386. >    pointers (which you shouldn't need to know), and with the
  387. >    complexities of function prototypes.  (Taking those complexities
  388. >    into account, we find that rule 2 is conservative, of course;
  389. >    but it doesn't hurt.)  Understand questions 5.1, 5.2, and 5.4,
  390. ==========
  391. <        f(a)
  392. <        char a[];
  393. ---
  394. >        void f(char a[])
  395.         { ... }
  396. ==========
  397. <        f(a)
  398. <        char *a;
  399. ---
  400. >        void f(char *a)
  401. ==========
  402. < A:    You can't, in C.  Array dimensions must be compile-time
  403. <    constants.  (gcc provides parameterized arrays as an extension.)
  404. <    You'll have to use malloc(), and remember to call free() before
  405. ---
  406. > A:    Until recently, you couldn't.  Array dimensions in C
  407. >    traditionally had to be compile-time constants.  C9X will
  408. >    introduce variable-length arrays (VLA's) which will solve this
  409. >    problem; local arrays may have sizes set by variables or other
  410. >    expressions, perhaps involving function parameters.  (gcc has
  411. >    provided parameterized arrays as an extension for some time.)
  412. >    If you can't use C9X or gcc, you'll have to use malloc(), and
  413. ==========
  414. < A:    It is usually best to allocate an array of pointers, and then
  415. ---
  416. > A:    The traditional solution is to allocate an array of pointers,
  417.     and then initialize each pointer to a dynamically-allocated
  418.     "row."  Here is a two-dimensional example:
  419. ==========
  420. <        int **array1 = (int **)malloc(nrows * sizeof(int *));
  421.         for(i = 0; i < nrows; i++)
  422. <            array1[i] = (int *)malloc(ncolumns * sizeof(int));
  423. ---
  424. >        int **array1 = malloc(nrows * sizeof(int *));
  425.         for(i = 0; i < nrows; i++)
  426. >            array1[i] = malloc(ncolumns * sizeof(int));
  427. ==========
  428. <        int **array2 = (int **)malloc(nrows * sizeof(int *));
  429. <        array2[0] = (int *)malloc(nrows * ncolumns * sizeof(int));
  430. ---
  431. >        int **array2 = malloc(nrows * sizeof(int *));
  432. >        array2[0] = malloc(nrows * ncolumns * sizeof(int));
  433. ==========
  434.     In either case, the elements of the dynamic array can be
  435.     accessed with normal-looking array subscripts: arrayx[i][j] (for
  436. <    0 <= i < NROWS and 0 <= j < NCOLUMNS).
  437. ---
  438. >    0 <= i < nrows and 0 <= j < ncolumns).
  439. ==========
  440. <        int *array3 = (int *)malloc(nrows * ncolumns * sizeof(int));
  441. ---
  442. >        int *array3 = malloc(nrows * ncolumns * sizeof(int));
  443. ==========
  444. <    Finally, you could use pointers to arrays:
  445. ---
  446. >    Yet another option is to use pointers to arrays:
  447. ==========
  448.         int (*array4)[NCOLUMNS] =
  449. <            (int (*)[NCOLUMNS])malloc(nrows * sizeof(*array4));
  450. ---
  451. >        int (*array4)[NCOLUMNS] = malloc(nrows * sizeof(*array4));
  452. ==========
  453. >    Finally, in C9X you can use a variable-length array.
  454. ==========
  455. >    References: C9X Sec. 6.5.5.2.
  456. ==========
  457. <        f(int a[][NCOLUMNS])
  458. ---
  459. >        void f(int a[][NCOLUMNS])
  460. ==========
  461. <        f(int (*ap)[NCOLUMNS])  /* ap is a pointer to an array */
  462. ---
  463. >        void f(int (*ap)[NCOLUMNS])    /* ap is a pointer to an array */
  464. ==========
  465. < A:    It's not easy.  One way is to pass in a pointer to the [0][0]
  466. ---
  467. > A:    It's not always easy.  One way is to pass in a pointer to the
  468.     [0][0] element, along with the two dimensions, and simulate
  469.     array subscripting "by hand":
  470. ==========
  471. <        f2(aryp, nrows, ncolumns)
  472. <        int *aryp;
  473. <        int nrows, ncolumns;
  474. ---
  475. >        void f2(int *aryp, int nrows, int ncolumns)
  476. ==========
  477. <    gcc allows local arrays to be declared having sizes which are
  478. <    specified by a function's arguments, but this is a nonstandard
  479. <    extension.
  480. ---
  481. >    C9X will allow variable-length arrays, and once compilers which
  482. >    accept C9X's extensions become widespread, this will probably
  483. >    become the preferred solution.  (gcc has supported variable-
  484. >    sized arrays for some time.)
  485. ==========
  486. <            free(listp);
  487. ---
  488. >            free((void *)listp);
  489. ==========
  490. < A:    There's no standard way, although it is a common need.  If the
  491. <    compiler documentation is unhelpful, the most expedient way is
  492. ---
  493. > A:    There's no standard way, although it is a common need.  gcc
  494. >    provides a -dM option which works with -E, and other compilers
  495. >    may provide something similar.  If the compiler documentation
  496. ==========
  497. >    C9X will introduce formal support for function-like macros with
  498. >    variable-length argument lists.  The notation ... will appear at
  499. >    the end of the macro "prototype" (just as it does for varargs
  500. >    functions), and the pseudomacro __VA_ARGS__ in the macro
  501. >    definition will be replaced by the variable arguments during
  502. >    invocation.
  503. ==========
  504. >    References: C9X Sec. 6.8.3, Sec. 6.8.3.1.
  505. ==========
  506.     More recently, the Standard has been adopted as an international
  507.     standard, ISO/IEC 9899:1990, and this ISO Standard replaces the
  508.     earlier X3.159 even within the United States (where it is known
  509. <    as ANSI/ISO 9899-1990 [1992]).  Its sections are numbered
  510. <    differently (briefly, ISO sections 5 through 7 correspond
  511. <    roughly to the old ANSI sections 2 through 4).  As an ISO
  512. ---
  513. >    as ANSI/ISO 9899-1990 [1992]).  As an ISO Standard, it is
  514.     subject to ongoing revision through the release of Technical
  515.     Corrigenda and Normative Addenda.
  516. ==========
  517. <    In 1994, Technical Corrigendum 1 amended the Standard in about
  518. <    40 places, most of them minor corrections or clarifications.
  519. <    More recently, Normative Addendum 1 added about 50 pages of new
  520. <    material, mostly specifying new library functions for
  521. <    internationalization.  The production of Technical Corrigenda is
  522. <    an ongoing process, and a second one is expected in late 1995.
  523. <    In addition, both ANSI and ISO require periodic review of their
  524. <    standards.  This process began in 1995, and will likely result
  525. <    in a completely revised standard (nicknamed "C9X" on the
  526. <    assumption of completion by 1999).
  527. ---
  528. >    In 1994, Technical Corrigendum 1 (TC1) amended the Standard
  529. >    in about 40 places, most of them minor corrections or
  530. >    clarifications, and Normative Addendum 1 (NA1) added about 50
  531. >    pages of new material, mostly specifying new library functions
  532. >    for internationalization.  In 1995, TC2 added a few more minor
  533. >    corrections.
  534. >
  535. >    As of this writing, a complete revision of the Standard is in
  536. >    its final stages.  The new Standard is nicknamed "C9X" on the
  537. >    assumption that it will be finished by the end of 1999.  (Many
  538. >    of this article's answers have been updated to reflect new C9X
  539. >    features.)
  540. ==========
  541.     including several of those covered here.  (The Rationale was
  542.     "not part of ANSI Standard X3.159-1989, but... included for
  543. <    information only," and is not included with the ISO Standard.)
  544. ---
  545. >    information only," and is not included with the ISO Standard.
  546. >    A new one is being prepared for C9X.)
  547. ==========
  548. < A:    Doing so is perfectly legal, as long as you're careful (see
  549. <    especially question 11.3).  Note however that old-style syntax
  550. ---
  551. > A:    Doing so is legal, but requires a certain amount of care (see
  552. >    especially question 11.3).  Modern practice, however, is to
  553. >    use the prototyped form in both declarations and definitions.
  554. >    (The old-style syntax is marked as obsolescent, so official
  555.     support for it may be removed some day.)
  556. ==========
  557. <        extern f(struct x *p);
  558. ---
  559. >        extern int f(struct x *p);
  560. ==========
  561.   11.9:    What's the difference between "const char *p" and
  562.     "char * const p"?
  563.  
  564. < A:    "char const *p" declares a pointer to a constant character (you
  565. ---
  566. > A:    "const char *p" (which can also be written "char const *p")
  567.     declares a pointer to a constant character (you can't change
  568.     the character); "char * const p" declares a constant pointer
  569.     to a (variable) character (i.e. you can't change the pointer).
  570. ==========
  571. >    It has been reported that programs using void main() and
  572. >    compiled using BC++ 4.5 can crash.  Some compilers (including
  573. >    DEC C V4.1 and gcc with certain warnings enabled) will complain
  574. >    about void main().
  575. ==========
  576.     the systems which have them.  The limitation is only that
  577.     identifiers be *significant* in the first six characters, not
  578.     that they be restricted to six characters in length.  This
  579. <    limitation is annoying, but certainly not unbearable, and is
  580. <    marked in the Standard as "obsolescent," i.e. a future revision
  581. <    will likely relax it.
  582. <
  583. <    This concession to current, restrictive linkers really had to be
  584. <    made, no matter how vehemently some people oppose it.  (The
  585. <    Rationale notes that its retention was "most painful.")  If you
  586. <    disagree, or have thought of a trick by which a compiler
  587. <    burdened with a restrictive linker could present the C
  588. <    programmer with the appearance of more significance in external
  589. <    identifiers, read the excellently-worded section 3.1.2 in the
  590. <    X3.159 Rationale (see question 11.1), which discusses several
  591. <    such schemes and explains why they could not be mandated.
  592. ---
  593. >    limitation is marked in the Standard as "obsolescent", and will
  594. >    be removed in C9X.
  595. ==========
  596. <    Finally, are you sure you really need to convert lots of old
  597. <    code to ANSI C?  The old-style function syntax is still
  598. <    acceptable (except for variadic functions; see section 15), and
  599. <    a hasty conversion can easily introduce bugs.  (See question
  600. <    11.3.)
  601. ==========
  602. < A:    There are not (yet) any good answers to either of these
  603. <    excellent questions, and this represents perhaps the biggest
  604. <    deficiency in the traditional stdio library.
  605. ==========
  606. <    12.10).  Several stdio's (including GNU and 4.4bsd) provide the
  607. <    obvious snprintf() function, which can be used like this:
  608. ---
  609. >    The "obvious" solution to the overflow problem is a length-
  610. >    limited version of sprintf(), namely snprintf().  It would be
  611.     used like this:
  612. ==========
  613. <    and we can hope that a future revision of the ANSI/ISO C
  614. <    Standard will include this function.
  615. ---
  616. >    snprintf() has been available in several stdio libraries
  617. >    (including GNU and 4.4bsd) for several years.  It will be
  618. >    standardized in C9X.
  619. ==========
  620. >    When the C9X snprintf() arrives, it will also be possible to use
  621. >    it to predict the size required for an arbitrary sprintf() call.
  622. >    C9X snprintf() will return the number of characters it would
  623. >    have placed in the buffer, not just how many it did place.
  624. >    Furthermore, it may be called with a buffer size of 0 and a
  625. >    null pointer as the destination buffer.  Therefore, the call
  626. >
  627. >        nch = snprintf(NULL, 0, fmtstring, /* other arguments */ );
  628. >
  629. >    will compute the number of characters required for the fully-
  630. >    formatted string.
  631. >
  632. >    References: C9X Sec. 7.13.6.6.
  633. ==========
  634. A:    ftell() and fseek() use type long int to represent offsets
  635. <    (positions) in a file, and are therefore limited to offsets of
  636. ---
  637. >    (positions) in a file, and may therefore be limited to offsets
  638.     of about 2 billion (2**31-1).  The newer fgetpos() and fsetpos()
  639. ==========
  640. >    fgetpos() and fsetpos() also record the state associated with
  641. >    multibyte streams.
  642. ==========
  643. >    It is barely possible to save away information about a stream
  644. >    before calling freopen(), such that the original stream can
  645. >    later be restored, but the methods involve system-specific calls
  646. >    such as dup(), or copying or inspecting the contents of a FILE
  647. >    structure, which is exceedingly nonportable and unreliable.
  648. ==========
  649. <        main()
  650. ---
  651. >        int main()
  652. ==========
  653. < A:    Here is one method, by Box and Muller, and recommended by Knuth:
  654. ---
  655. > A:    Here is one method, recommended by Knuth and due originally to
  656. >    Marsaglia:
  657. ==========
  658. <    References: Knuth Sec. 3.4.1 p. 117; Box and Muller, "A Note on
  659. <    the Generation of Random Normal Deviates";
  660. ---
  661. >    References: Knuth Sec. 3.4.1 p. 117; Marsaglia and Bray,
  662. >    "A Convenient Method for Generating Normal Variables";
  663. ==========
  664. >    C9X will provide isnan(), fpclassify(), and several other
  665. >    classification routines.
  666. ==========
  667. >    References: C9X Sec. 7.7.3.
  668. ==========
  669.   A:    It is straightforward to define a simple structure and some
  670. <    arithmetic functions to manipulate them.  See also questions
  671. ---
  672. >    arithmetic functions to manipulate them.  C9X will support
  673. >    complex as a standard type.  See also questions 2.7, 2.10, and
  674. ==========
  675. >    References: C9X Sec. 6.1.2.5, Sec. 7.8.
  676. ==========
  677. < A:    Unfortunately, vscanf and the like are not standard.  You're on
  678. <    your own.
  679. ---
  680. > A:    C9X will support vscanf(), vfscanf(), and vsscanf().
  681. >    (Until then, you may be on your own.)
  682. ==========
  683. >    References: C9X Secs. 7.3.6.12-14.
  684. ==========
  685. >    Tom Torfs has a nice tutorial at
  686. >    http://members.xoom.com/tomtorfs/cintro.html .
  687. ==========
  688. >    Many comp.lang.c regulars recommend _C: A Modern Approach_,
  689. >    by K.N. King.
  690. ==========
  691. >    Scott McMahon has a nice set of reviews at
  692. >    http://www.skwc.com/essent/cyberreviews.html .
  693. ==========
  694.   A:    Once upon a time, Unix had a fairly nice little set of device-
  695. <    independent plot routines described in plot(3) and plot(5), but
  696. <    they've largely fallen into disuse.
  697. ---
  698. >    independent plot functions described in plot(3) and plot(5).
  699. >    The GNU libplot package maintains the same spirit and supports
  700. >    many modern plot devices;
  701. >    see http://www.gnu.org/software/plotutils/plotutils.html .
  702. ==========
  703.     solution is simply to rewrite the file.  (Instead of deleting
  704.     records, you might consider simply marking them as deleted, to
  705. <    avoid rewriting.)  See also questions 12.30 and 19.13.
  706. ---
  707. >    avoid rewriting.)  Another possibility, of course, is to use a
  708. >    database instead of a flat file.  See also questions 12.30 and
  709. ==========
  710.     to allocate huge amounts of it contiguously.  (The C Standard
  711. <    does not guarantee that single objects can be 32K or larger.)
  712. ---
  713. >    does not guarantee that single objects can be 32K or larger,
  714. >    or 64K for C9X.)
  715. ==========
  716.     and W. R. Stevens's _UNIX Network Programming_.  (There is also
  717. <    plenty of information out on the net itself.)
  718. ---
  719. >    plenty of information out on the net itself, including the
  720. >    "Unix Socket FAQ" at http://kipper.york.ac.uk/~vic/sock-faq/ .)
  721. ==========
  722. <        dayofweek(y, m, d)    /* 0 = Sunday */
  723. <        int y, m, d;        /* 1 <= m <= 12, y > 1752 or so */
  724. ---
  725. >        int dayofweek(int y, int m, int d)    /* 0 = Sunday */
  726. ==========
  727. < A:    The contest schedule is tied to the dates of the USENIX
  728. <    conferences at which the winners are announced.  At the time of
  729. <    this writing, it is expected that the yearly contest will open
  730. <    in October.  To obtain a current copy of the rules and
  731. <    guidelines, send e-mail with the Subject: line "send rules" to:
  732. <
  733. <        {apple,pyramid,sun,uunet}!hoptoad!judges  or
  734. <        judges@toad.com
  735. <
  736. <    (Note that these are *not* the addresses for submitting
  737. <    entries.)
  738. ---
  739. > A:    The contest is in a state of flux; see
  740. >    http://www.ioccc.org/index.html for current details.
  741. ==========
  742. <    Contest winners should be announced at the USENIX conference in
  743. <    January, and are posted to the net sometime thereafter.  Winning
  744. ---
  745. >    Contest winners are usually announced at a Usenix conference,
  746.     and are posted to the net sometime thereafter.  Winning entries
  747.     from previous years (back to 1984) are archived at ftp.uu.net
  748. ==========
  749. <    see also http://reality.sgi.com/csp/ioccc/ .
  750. --
  751. >    see also http://www.ioccc.org/index.html .
  752. ==========
  753. <    As a last resort, previous winners may be obtained by sending e-
  754. <    mail to the above address, using the Subject: "send YEAR
  755. <    winners", where YEAR is a single four-digit year, a year range,
  756. <    or "all".
  757.         int dayofweek(int y, int m, int d)    /* 0 = Sunday */
  758. ==========
  759.  
  760.  
  761. Finally, the not-so-significant changes:
  762.  
  763. ==========
  764. < [Last modified September 5, 1996 by scs.]
  765. ---
  766. > [Last modified February 7, 1999 by scs.]
  767. ==========
  768. < This article is Copyright 1990-1996 by Steve Summit.  Content from the
  769. ---
  770. > This article is Copyright 1990-1999 by Steve Summit.  Content from the
  771. ==========
  772.   Besides listing frequently-asked questions, this article also summarizes
  773.   frequently-posted answers.  Even if you know all the answers, it's worth
  774.   skimming through this list once in a while, so that when you see one of
  775.   its questions unwittingly posted, you won't have to waste time
  776. > answering.
  777. ---
  778. > answering.  (However, this is a large and heavy document, so don't
  779. > assume that everyone on the newsgroup has managed to read all of it in
  780. > detail, and please don't roll it up and thwack people over the head with
  781. > it just because they missed their answer in it.)
  782. ==========
  783. < This article was last modified on September 5, 1996, and its travels
  784. < may have taken it far from its original home on Usenet.  It may now
  785. ---
  786. > This article was last modified on February 6, 1999, and its travels may
  787. > have taken it far from its original home on Usenet.  It may, however,
  788.   be out-of-date, particularly if you are looking at a printed copy
  789. ==========
  790.   retrieved from a tertiary archive site or CD-ROM.  You should be able to
  791. < obtain the most up-to-date copy by anonymous ftp from sites ftp.eskimo.com,
  792. < rtfm.mit.edu, or ftp.uu.net (see questions 18.16 and 20.40), or by
  793. < sending the e-mail message "help" to mail-server@rtfm.mit.edu .
  794. ---
  795. > be able to obtain the most up-to-date copy on the web at
  796. > http://www.eskimo.com/~scs/C-faq/top.html or http://www.faqs.org/faqs/ ,
  797. > or from one of the ftp sites mentioned in question 20.40.
  798. ==========
  799.   of differences with respect to the previous version.  A hypertext
  800. < version is available on the world-wide web (WWW); see URL
  801. < http://www.eskimo.com/~scs/C-faq/top.html .  Finally, for those who
  802. ---
  803. > is available on the web at the aforementioned URL.  Finally, for those
  804. ==========
  805. < 1.7:    What's the best way to declare and define global variables?
  806. ---
  807. > 1.7:    What's the best way to declare and define global variables
  808. >    and functions?
  809. ==========
  810.         cdecl can also explain complicated declarations, help with
  811.         casts, and indicate which set of parentheses the arguments
  812.         go in (for complicated function definitions, like the one
  813. <        above).  Versions of cdecl are in volume 14 of
  814. <        comp.sources.unix (see question 18.16) and K&R2.
  815. ---
  816. >        above).  See question 18.1.
  817. ==========
  818. > 1.25b: What's the right declaration for main()?
  819. >    Is void main() correct?
  820. >
  821. > A:    See questions 11.12a to 11.15.  (But no, it's not correct.)
  822. ==========
  823. < 1.30:    What can I safely assume about the initial values of variables
  824. ---
  825. > 1.30:    What am I allowed to assume about the initial values
  826.     of variables which are not explicitly initialized?
  827. ==========
  828.   1.31:    This code, straight out of a book, isn't compiling:
  829.  
  830. <        f()
  831. ---
  832. >        int f()
  833.         {
  834.             char a[] = "Hello, world!";
  835. ==========
  836.   A:    Perhaps you have a pre-ANSI compiler, which doesn't allow
  837.     initialization of "automatic aggregates" (i.e. non-static local
  838. <    arrays, structures, and unions).  As a workaround, you can make
  839. <    the array global or static (if you won't need a fresh copy
  840. <    during any subsequent calls), or replace it with a pointer (if
  841. <    the array won't be written to).  (You can always initialize
  842. <    local char * variables to point to string literals, but see
  843. <    question 1.32 below.)  If neither of these conditions hold,
  844. <    you'll have to initialize the array by hand with strcpy() when
  845. ---
  846. >    arrays, structures, and unions).  (As a workaround, and
  847. >    depending on how the variable a is used, you may be able to make
  848. >    it global or static, or replace it with a pointer, or initialize
  849. >    it by hand with strcpy() when f() is called.)  See also
  850. >    question 11.29.
  851. ==========
  852. < 1.31a: What's wrong with this initialization?
  853. ---
  854. > 1.31b: What's wrong with this initialization?
  855. ==========
  856. < A:    Is it in the declaration of a static or non-local variable?
  857. <    Function calls are not allowed in initializers for such
  858. <    variables.
  859. ---
  860. > A:    Is the declaration of a static or non-local variable?  Function
  861. >    calls are allowed only in initializers for automatic variables
  862. >    (that is, for local, non-static variables).
  863. ==========
  864.   A:    The first form declares a "structure tag"; the second declares a
  865.     "typedef".  The main difference is that you subsequently refer
  866. <    to the first type as "struct x1" and the second as "x2".  That
  867. ---
  868. >    to the first type as "struct x1" and the second simply as "x2".
  869. ==========
  870.   2.7:    I heard that structures could be assigned to variables and
  871.     passed to and from functions, but K&R1 says not.
  872.  
  873. < A:    What K&R1 said was that the restrictions on structure operations
  874. ---
  875. > A:    What K&R1 said (though this was quite some time ago by now) was
  876.     that the restrictions on structure operations would be lifted
  877. ==========
  878. <    Ritchie's compiler even as K&R1 was being published.  Although a
  879. <    few early C compilers lacked these operations, all modern
  880. ---
  881. >    compiler even as K&R1 was being published.  A few ancient C
  882. >    compilers may have lacked these operations, but all modern
  883.     compilers support them, and they are part of the ANSI C
  884. ==========
  885.     (Note that when a structure is assigned, passed, or returned,
  886. <    the copying is done monolithically; anything pointed to by any
  887. ---
  888. >    the copying is done monolithically; the data pointed to by any
  889.     pointer fields is *not* copied.)
  890. ==========
  891. < 2.8:    Why can't you compare structures?
  892. <
  893. < A:    There is no single, good way for a compiler to implement
  894. ---
  895. > 2.8:    Is there a way to compare structures automatically?
  896. >
  897. > A:    No.  There is no single, good way for a compiler to implement
  898. ==========
  899. <    structure comparison which is consistent with C's low-level
  900. ---
  901. >    implicit structure comparison (i.e. to support the == operator
  902. >    for structures) which is consistent with C's low-level flavor.
  903. ==========
  904. < 2.9:    How are structure passing and returning implemented?
  905. <
  906. < A:    When structures are passed as arguments to functions, the entire
  907. <    structure is typically pushed on the stack, using as many words
  908. <    as are required.  (Programmers often choose to use pointers to
  909. <    structures instead, precisely to avoid this overhead.)  Some
  910. <    compilers merely pass a pointer to the structure, though they
  911. <    may have to make a local copy to preserve pass-by-value
  912. <    semantics.
  913. <
  914. <    Structures are often returned from functions in a location
  915. <    pointed to by an extra, compiler-supplied "hidden" argument to
  916. <    the function.  Some older compilers used a special, static
  917. <    location for structure returns, although this made structure-
  918. <    valued functions non-reentrant, which ANSI C disallows.
  919. <
  920. <    References: ANSI Sec. 2.2.3; ISO Sec. 5.2.3.
  921. ==========
  922. <    (Under pre-ANSI C, a (char *) cast on the first argument is
  923. <    required.  What's important is that fwrite() receive a byte
  924. <    pointer, not a structure pointer.)
  925. ==========
  926.     Even when the structure is not part of an array, the end padding
  927.     remains, so that sizeof can always return a consistent size.
  928. >    See also question 2.12 above.
  929. ==========
  930.     intervening comment.)  Since structure-valued functions are
  931. <    usually implemented by adding a hidden return pointer (see
  932. <    question 2.9), the generated code for main() tries to accept
  933. ---
  934. >    usually implemented by adding a hidden return pointer, the
  935.     generated code for main() tries to accept three arguments,
  936. ==========
  937. < A:    At the present time, there is little difference.  Although many
  938. <    people might have wished otherwise, the C Standard says that
  939. ---
  940. > A:    At the present time, there is little difference.  The C Standard
  941.     says that enumerations may be freely intermixed with other
  942. ==========
  943. <    without errors.  (If such intermixing were disallowed without
  944. ---
  945. >    integral types, without errors.  (If, on the other hand, such
  946.     intermixing were disallowed without explicit casts, judicious
  947. ==========
  948. <    constant to a string.  (If all you're worried about is
  949. <    debugging, a good debugger should automatically print
  950. ---
  951. >    constant to a string.  (For debugging purposes, a good debugger
  952.     should automatically print enumeration constants symbolically.)
  953. ==========
  954. A:    The subexpression i++ causes a side effect -- it modifies i's
  955.     value -- which leads to undefined behavior since i is also
  956. <    referenced elsewhere in the same expression.
  957. ---
  958. >    referenced elsewhere in the same expression, and there's no way
  959. >    to determine whether the reference (in a[i] on the left-hand
  960. >    side) should be to the old or the new value.
  961. ==========
  962.   3.3:    I've experimented with the code
  963.         int i = 3;
  964.         i = i++;
  965. <    on several compilers.  Some gave i the value 3, some gave 4, but
  966. <    one gave 7.  I know the behavior is undefined, but how could it
  967. <    give 7?
  968. ---
  969. >    on several compilers.  Some gave i the value 3, and some gave 4.
  970. >    Which compiler is correct?
  971. ==========
  972. < A:    Undefined behavior means *anything* can happen.  See questions
  973. ---
  974. > A:    There is no correct answer; the expression is undefined.  See
  975. >    questions 3.1, 3.8, 3.9, and 11.33.
  976. ==========
  977. < A:    A sequence point is the point (at the end of a full expression,
  978. ---
  979. > A:    A sequence point is a point in time (at the end of the
  980. >    evaluation of a full expression, or at the ||, &&, ?:, or comma
  981. ==========
  982.     A similar problem can arise when two integers are divided, with
  983. <    the result assigned to a floating-point variable.
  984. ---
  985. >    the result assigned to a floating-point variable; the solution
  986. >    is similar, too.
  987. ==========
  988. < A:    Unary operators like *, ++, and -- all associate (group) from
  989. <    right to left.  Therefore, *p++ increments p (and returns the
  990. <    value pointed to by p before the increment).  To increment the
  991. ---
  992. > A:    Postfix ++ essentially has higher precedence than the prefix
  993. >    unary operators.  Therefore, *p++ is equivalent to *(p++); it
  994. >    increments p, and returns the value which p pointed to before p
  995. >    was incremented.  To increment the value pointed to by p, use
  996. ==========
  997. <    assigned to, or incremented with ++.  (It is an anomaly in pcc-
  998. <    derived compilers, and an extension in gcc, that expressions
  999. <    such as the above are ever accepted.)  Say what you mean: use
  1000. ---
  1001. >    assigned to, or incremented with ++.  (It is either an accident
  1002. >    or a delibrate but nonstandard extension if a particular
  1003. >    compiler accepts expressions such as the above.)  Say what you
  1004. ==========
  1005. < 4.9:    Can I use a void ** pointer to pass a generic pointer to a
  1006. <    function by reference?
  1007. ---
  1008. > 4.9:    Can I use a void ** pointer as a parameter so that a function
  1009. >    can accept a generic pointer by reference?
  1010. ==========
  1011.     and from void *'s; these conversions cannot be performed (the
  1012.     correct underlying pointer type is not known) if an attempt is
  1013. <    made to indirect upon a void ** value which points at something
  1014. <    other than a void *.
  1015. ---
  1016. >    made to indirect upon a void ** value which points at a pointer
  1017. >    type other than void *.
  1018. ==========
  1019.     You can simulate pass by reference yourself, by defining
  1020.     functions which accept pointers and then using the & operator
  1021.     when calling, and the compiler will essentially simulate it for
  1022.     you when you pass an array to a function (by passing a pointer
  1023. <    instead, see question 6.4 et al.), but C has nothing truly
  1024. ---
  1025. >    instead, see question 6.4 et al.).  However, C has nothing truly
  1026.     equivalent to formal pass by reference or C++ reference
  1027. ==========
  1028. <    parameters.  (However, function-like preprocessor macros do
  1029. ---
  1030. >    parameters.  (On the other hand, function-like preprocessor
  1031. >    macros can provide a form of "pass by name".)
  1032. ==========
  1033.     It can also be argued that functions are always called via
  1034.     pointers, and that "real" function names always decay implicitly
  1035.     into pointers (in expressions, as they do in initializations;
  1036. <    see question 1.34).  This reasoning, made widespread through pcc
  1037. <    and adopted in the ANSI standard, means that
  1038. ---
  1039. >    see question 1.34).  This reasoning (which is in fact used in
  1040.     the ANSI standard) means that
  1041. ==========
  1042. <    function pointed to.)  An explicit * is still allowed (and
  1043. <    recommended, if portability to older compilers is important).
  1044. ---
  1045. >    function pointed to.)  An explicit * is still allowed.
  1046. ==========
  1047. < A:    When C requires the Boolean value of an expression (in the if,
  1048. <    while, for, and do statements, and with the &&, ||, !, and ?:
  1049. <    operators), a false value is inferred when the expression
  1050. ---
  1051. > A:    When C requires the Boolean value of an expression, a false
  1052.     value is inferred when the expression compares equal to zero,
  1053. ==========
  1054. A:    As a matter of style, many programmers prefer not to have
  1055.     unadorned 0's scattered through their programs.  Therefore, the
  1056. <    preprocessor macro NULL is #defined (by <stdio.h> or <stddef.h>)
  1057. ---
  1058. >    preprocessor macro NULL is #defined (by <stdio.h> and several
  1059. >    other headers) with the value 0,
  1060. ==========
  1061. < A:    The same as on any other machine: as 0 (or ((void *)0)).
  1062. ---
  1063. > A:    The same as on any other machine: as 0 (or some version of 0;
  1064. >    see question 5.4).
  1065. ==========
  1066. < A:    Not in general.  The problem is that there are machines which
  1067. ---
  1068. > A:    Not in general.  The complication is that there are machines
  1069.     which use different internal representations for pointers to
  1070.     different types of data.
  1071. ==========
  1072. <    not buy much.  It is not needed in assignments and comparisons;
  1073. <    see question 5.2.  It does not even save keystrokes.  Its use
  1074. <    may suggest to the reader that the program's author is shaky on
  1075. <    the subject of null pointers, requiring that the #definition of
  1076. <    the macro, its invocations, and *all* other pointer usages be
  1077. <    checked.  See also questions 9.1 and 10.2.
  1078. ---
  1079. >    not buy much.  It is not needed in assignments or comparisons;
  1080. >    see question 5.2.  (It does not even save keystrokes.)  See also
  1081.     questions 9.1 and 10.2.
  1082. ==========
  1083. <    4.    The NULL macro, which is #defined to be "0" or
  1084. <        "((void *)0)" (see question 5.4).  Finally, as red
  1085. ---
  1086. >    4.    The NULL macro, which is #defined to be 0 (see question
  1087.         5.4).  Finally, as red herrings, we have...
  1088. ==========
  1089. < A:    C programmers traditionally like to know more than they need to
  1090. ---
  1091. > A:    C programmers traditionally like to know more than they might
  1092.     need to about the underlying machine implementation.  The fact
  1093. ==========
  1094.     One good way to wade out of the confusion is to imagine that C
  1095.     used a keyword (perhaps "nil", like Pascal) as a null pointer
  1096.     constant.  The compiler could either turn "nil" into the
  1097. <    correct type of null pointer when it could determine the type
  1098. ---
  1099. >    appropriate type of null pointer when it could unambiguously
  1100. >    determine that type from the source code, or complain when it
  1101.     could not.
  1102. ==========
  1103.   5.20:    What does a run-time "null pointer assignment" error mean?  How
  1104. <    do I track it down?
  1105. ---
  1106. >    can I track it down?
  1107. ==========
  1108. < A:    This message, which typically occurs with MS-DOS compilers (see,
  1109. <    therefore, section 19) means that you've written, via a null
  1110. ---
  1111. > A:    This message, which typically occurs with MS-DOS compilers, means
  1112.     that you've written, via a null (perhaps because uninitialized)
  1113.     pointer, to an invalid location
  1114. ==========
  1115. <    A debugger may let you set a data breakpoint or watchpoint or
  1116. <    something on location 0.  Alternatively, you could write a bit
  1117. ---
  1118. >    A debugger may let you set a data watchpoint on location 0.
  1119.     Alternatively, you could write a bit of code to stash away a
  1120. ==========
  1121. < A:    The declaration extern char *a simply does not match the actual
  1122. ---
  1123. > A:    In one source file you defind an array of characters and in the
  1124. >    other you declared a pointer to characters.  The declaration
  1125.     extern char *a simply does not match the actual definition.
  1126. ==========
  1127.   A:    Much of the confusion surrounding arrays and pointers in C can
  1128.     be traced to a misunderstanding of this statement.  Saying that
  1129.     arrays and pointers are "equivalent" means neither that they are
  1130. <    identical nor even interchangeable.
  1131. ---
  1132. >    identical nor even interchangeable.  What it means is that array
  1133. >    and pointer arithmetic is defined such that a pointer can be
  1134. >    conveniently used to access an array or to simulate an array.
  1135. ==========
  1136. <    "Equivalence" refers to the following key definition:
  1137. ---
  1138. >    Specifically, the cornerstone of the equivalence is this key
  1139.     definition:
  1140. ==========
  1141. >    That is, whenever an array appears in an expression,
  1142. >    the compiler implicitly generates a pointer to the array's
  1143. >    first element, just as if the programmer had written &a[0].
  1144. ==========
  1145. <    See also question 6.8.
  1146. ---
  1147. >    See also questions 6.8 and 6.14.
  1148. ==========
  1149.     Since arrays decay immediately into pointers, an array is never
  1150.     actually passed to a function.  Allowing pointer parameters to
  1151.     be declared as arrays is a simply a way of making it look as
  1152. <    though the array was being passed -- a programmer may wish to
  1153. <    emphasize that a parameter is traditionally treated as if it
  1154. <    were an array, or that an array (strictly speaking, the address)
  1155. <    is traditionally passed.  As a convenience, therefore, any
  1156. ---
  1157. >    though an array was being passed, perhaps because the parameter
  1158. >    will be used within the function as if it were an array.
  1159. >    Specifically, any parameter declarations which "look like"
  1160.     arrays, e.g.
  1161. ==========
  1162.     declarations, nowhere else.  If the conversion bothers you,
  1163. <    avoid it; many people have concluded that the confusion it
  1164. ---
  1165. >    avoid it; many programmers have concluded that the confusion it
  1166.     causes outweighs the small advantage of having the declaration
  1167. ==========
  1168.     (and if the call to malloc() succeeds), you can reference
  1169. <    dynarray[i] (for i from 0 to 9) just as if dynarray were a
  1170. <    conventional, statically-allocated array (int a[10]).
  1171. ---
  1172. >    dynarray[i] (for i from 0 to 9) almost as if dynarray were a
  1173. >    conventional, statically-allocated array (int a[10]).  The only
  1174. >    difference is that sizeof will not give the size of the "array".
  1175. ==========
  1176.   A:    Although this technique is attractive (and was used in old
  1177. <    editions of the book _Numerical Recipes in C_), it does not
  1178. <    conform to the C standards.  Pointer arithmetic is defined only
  1179. ---
  1180. >    editions of the book _Numerical Recipes in C_), it is not
  1181. >    strictly conforming to the C Standard.  Pointer arithmetic is
  1182. ==========
  1183.     pointer to a pointer.  Pointers to arrays can be confusing, and
  1184. <    must be treated carefully; see also question 6.13.  (The
  1185. <    confusion is heightened by the existence of incorrect compilers,
  1186. <    including some old versions of pcc and pcc-derived lints, which
  1187. <    improperly accept assignments of multi-dimensional arrays to
  1188. <    multi-level pointers.)
  1189. ---
  1190. >    must be treated carefully; see also question 6.13.
  1191. ==========
  1192.     pointer declaration is explicit.  Since the called function does
  1193.     not allocate space for the array, it does not need to know the
  1194.     overall size, so the number of rows, NROWS, can be omitted.  The
  1195. <    "shape" of the array is still important, so the column dimension
  1196. ---
  1197. >    width of the array is still important, so the column dimension
  1198.     NCOLUMNS (and, for three- or more dimensional arrays, the
  1199.     intervening ones) must be retained.
  1200. ==========
  1201.     If a function is already declared as accepting a pointer to a
  1202. <    pointer, it is probably meaningless to pass a two-dimensional
  1203. ---
  1204. >    pointer, it is almost certainly meaningless to pass a two-
  1205.     dimensional array directly to it.
  1206. ==========
  1207. <        f1(int a[][NCOLUMNS], int nrows, int ncolumns);
  1208. ---
  1209. >        void f1a(int a[][NCOLUMNS], int nrows, int ncolumns);
  1210. >        void f1b(int (*a)[NCOLUMNS], int nrows, int ncolumns);
  1211. ==========
  1212. <        f2(int *aryp, int nrows, int ncolumns);
  1213. ---
  1214. >        void f2(int *aryp, int nrows, int ncolumns);
  1215. ==========
  1216. <        f3(int **pp, int nrows, int ncolumns);
  1217. ---
  1218. >        void f3(int **pp, int nrows, int ncolumns);
  1219. ==========
  1220. <    where f1() accepts a conventional two-dimensional array, f2()
  1221. ---
  1222. >    where f1a() and f1b() accept conventional two-dimensional
  1223. >    arrays, f2() accepts a "flattened" two-dimensional array, and
  1224. ==========
  1225. <        f1(array, NROWS, NCOLUMNS);
  1226. <        f1(array4, nrows, NCOLUMNS);
  1227. ---
  1228. >        f1a(array, NROWS, NCOLUMNS);
  1229. >        f1b(array, NROWS, NCOLUMNS);
  1230. >        f1a(array4, nrows, NCOLUMNS);
  1231. >        f1b(array4, nrows, NCOLUMNS);
  1232. ==========
  1233. <    The following two calls would probably work on most systems, but
  1234. ---
  1235. >    The following calls would probably work on most systems, but
  1236. ==========
  1237. <        f1((int (*)[NCOLUMNS])(*array2), nrows, ncolumns);
  1238. <        f1((int (*)[NCOLUMNS])array3, nrows, ncolumns);
  1239. ---
  1240. >        f1a((int (*)[NCOLUMNS])(*array2), nrows, ncolumns);
  1241. >        f1a((int (*)[NCOLUMNS])(*array2), nrows, ncolumns);
  1242. >        f1b((int (*)[NCOLUMNS])array3, nrows, ncolumns);
  1243. >        f1b((int (*)[NCOLUMNS])array3, nrows, ncolumns);
  1244. ==========
  1245.     Since strcat() returns the value of its first argument (s1, in
  1246. <    this case), the variable s3 is superfluous.
  1247. ---
  1248. >    this case), the variable s3 is superfluous; after the call to
  1249. >    strcat(), s1 contains the result.
  1250. ==========
  1251.     an implementor than the invocations used by the caller.  In
  1252.     particular, many functions which accept pointers (e.g. to
  1253. <    structures or strings) are usually called with the address of
  1254. ---
  1255. >    structures or strings) are usually called with a pointer to some
  1256. ==========
  1257. <    some object (a structure, or an array -- see questions 6.3 and
  1258. <    6.4).  Other common examples are time() (see question 13.12)
  1259. ---
  1260. >    object (a structure, or an array -- see questions 6.3 and 6.4)
  1261. >    which the caller has allocated.  Other common examples are
  1262.     time() (see question 13.12) and stat().
  1263. ==========
  1264. < 7.5:    I have a function that is supposed to return a string, but when
  1265. ---
  1266. > 7.5a:    I have a function that is supposed to return a string, but when
  1267.     it returns to its caller, the returned string is garbage.
  1268. ==========
  1269. < A:    Make sure that the pointed-to memory is properly allocated.  The
  1270. <    returned pointer should be to a statically-allocated buffer, or
  1271. <    to a buffer passed in by the caller, or to memory obtained with
  1272. <    malloc(), but *not* to a local (automatic) array.  In other
  1273. <    words, never do something like
  1274. ---
  1275. > A:    Make sure that the pointed-to memory is properly allocated.
  1276. >    For example, make sure you have *not* done something like
  1277. ==========
  1278. >    See also questions 7.5b, 12.21, and 20.1.
  1279. ==========
  1280. > 7.5b:    So what's the right way to return a string or other aggregate?
  1281. >
  1282. > A:    The returned pointer should be to a statically-allocated buffer,
  1283. >    or to a buffer passed in by the caller, or to memory obtained
  1284. >    with malloc(), but *not* to a local (automatic) array.
  1285. >
  1286. >    See also question 20.1.
  1287. ==========
  1288.     Under ANSI/ISO Standard C, these casts are no longer necessary,
  1289.     and in fact modern practice discourages them, since they can
  1290.     camouflage important warnings which would otherwise be generated
  1291.     if malloc() happened not to be declared correctly; see question
  1292. <    7.6 above.
  1293. ---
  1294. >    7.6 above.  (However, the casts are typically seen in C code
  1295. >    which for one reason or another is intended to be compatible
  1296. >    with C++, where explicit casts from void * are required.)
  1297. ==========
  1298.   A:    Notice that 300 x 300 is 90,000, which will not fit in a 16-bit
  1299. <    int, even before you multiply it by sizeof(double) (see question
  1300. <    1.1).  If you need to allocate this much memory, you'll have to
  1301. ---
  1302. >    int, even before you multiply it by sizeof(double).  If you need
  1303.     to allocate this much memory, you'll have to be careful.
  1304. ==========
  1305.     question 3.14).  Otherwise, you'll have to break your data
  1306. <    structure up into smaller chunks, or use a 32-bit machine, or
  1307. ---
  1308. >    smaller chunks, or use a 32-bit machine or compiler, or use some
  1309. ==========
  1310. <    use some nonstandard memory allocation routines.  See also
  1311. ---
  1312. >    nonstandard memory allocation functions.  See also question
  1313. ==========
  1314. A:    Under the segmented architecture of PC compatibles, it can be
  1315. <    difficult to use more than 640K with any degree of transparency.
  1316. ---
  1317. >    difficult to use more than 640K with any degree of transparency,
  1318. >    especially under MS-DOS.
  1319. ==========
  1320.   7.19:    My program is crashing, apparently somewhere down inside malloc,
  1321. <    but I can't see anything wrong with it.
  1322. ---
  1323. >    but I can't see anything wrong with it.  Is there a bug in
  1324. >    malloc()?
  1325. ==========
  1326. <    problems may involve using pointers to freed storage, freeing
  1327. ---
  1328. >    problems may involve using pointers to memory that has been
  1329. >    freed, freeing pointers twice, freeing pointers not obtained
  1330. ==========
  1331. < 7.22:    When I call malloc() to allocate memory for a local pointer, do
  1332. <    I have to explicitly free() it?
  1333. ---
  1334. > 7.22:    When I call malloc() to allocate memory for a pointer which is
  1335. >    local to a function, do I have to explicitly free() it?
  1336. ==========
  1337.   7.24:    Must I free allocated memory before the program exits?
  1338.  
  1339.   A:    You shouldn't have to.  A real operating system definitively
  1340. <    reclaims all memory when a program exits.  Nevertheless, some
  1341. ---
  1342. >    reclaims all memory and other resources when a program exits.
  1343. ==========
  1344.   7.25:    I have a program which mallocs and later frees a lot of memory,
  1345. <    but memory usage (as reported by ps) doesn't seem to go back
  1346. ---
  1347. >    but I can see from the operating system that memory usage
  1348. >    doesn't actually go back down.
  1349. ==========
  1350.   A:    Most implementations of malloc/free do not return freed memory
  1351. <    to the operating system (if there is one), but merely make it
  1352. ---
  1353. >    to the operating system, but merely make it available for future
  1354.     malloc() calls within the same program.
  1355. ==========
  1356.   A:    The malloc/free implementation remembers the size of each block
  1357. <    allocated and returned, so it is not necessary to remind it of
  1358. ---
  1359. >    as it is allocated, so it is not necessary to remind it of the
  1360.     size when freeing.
  1361. ==========
  1362. < A:    Not portably.
  1363. ---
  1364. > A:    Unfortunately, there is no standard or portable way.
  1365. ==========
  1366. <    need a conversion routine: if you have the character, you have
  1367. ---
  1368. >    need a conversion function: if you have the character, you have
  1369. ==========
  1370.   A:    Perhaps surprisingly, character constants in C are of type int,
  1371. <    so sizeof('a') is sizeof(int) (though it's different in C++).
  1372. ---
  1373. >    so sizeof('a') is sizeof(int) (though this is another area
  1374. >    where C++ differs).  See also question 7.8.
  1375. ==========
  1376. < Section 9. Boolean Expressions
  1377. ---
  1378. > Section 9. Boolean Expressions and Variables
  1379. ==========
  1380.     would work as expected (as long as TRUE is 1), but it is
  1381. <    obviously silly.  In general, explicit tests against TRUE and
  1382. <    FALSE are inappropriate, because some library functions
  1383. ---
  1384. >    obviously silly.  In fact, explicit tests against TRUE and
  1385. >    FALSE are generally inappropriate, because some library
  1386. ==========
  1387. <    On the other hand, Boolean values and definitions can evidently
  1388. <    be confusing, and some programmers feel that TRUE and FALSE
  1389. <    macros only compound the confusion.  (See also question 5.9.)
  1390. ---
  1391. >    Although the use of macros like TRUE and FALSE (or YES
  1392. >    and NO) seems clearer, Boolean values and definitions can
  1393. >    be sufficiently confusing in C that some programmers feel
  1394. >    that TRUE and FALSE macros only compound the confusion, and
  1395. >    prefer to use raw 1 and 0 instead.  (See also question 5.9.)
  1396. ==========
  1397.   A:    There is no good answer to this question.  If the values are
  1398.     integers, a well-known trick using exclusive-OR could perhaps be
  1399.     used, but it will not work for floating-point values or
  1400. <    pointers, or if the two values are the same variable (and the
  1401. <    "obvious" supercompressed implementation for integral types
  1402. <    a^=b^=a^=b is illegal due to multiple side-effects; see question
  1403. <    3.2).  If the macro is intended to be used on values of
  1404. ---
  1405. >    pointers, or if the two values are the same variable.  (See
  1406. >    questions 3.3b and 20.15c.)  If the macro is intended to be
  1407. ==========
  1408.     arbitrary type (the usual goal), it cannot use a temporary,
  1409.     since it does not know what type of temporary it needs (and
  1410. <    would have a hard time naming it if it did), and standard C does
  1411. ---
  1412. >    it needs (and would have a hard time picking a name for it if
  1413.     it did), and standard C does not provide a typeof operator.
  1414. ==========
  1415.     On the other hand, when a definition or declaration should
  1416. <    remain private to one source file, it's fine to leave it there.
  1417. ---
  1418. >    remain private to one .c file, it's fine to leave it there.
  1419. ==========
  1420. > 10.8a:  What's the difference between #include <> and #include "" ?
  1421. >
  1422. > A:    The <> syntax is typically used with Standard or system-supplied
  1423. >    headers, while "" is typically used for a program's own header
  1424. >    files.
  1425. ==========
  1426. < 10.8:    Where are header ("#include") files searched for?
  1427. ---
  1428. > 10.8b:  What are the complete rules for header file searching?
  1429. ==========
  1430. > 10.10b: I'm #including the right header file for the library function
  1431. >    I'm using, but the linker keeps saying it's undefined.
  1432. >
  1433. > A:    See question 13.25.
  1434. ==========
  1435.   A:    You can't do it directly; preprocessor #if arithmetic uses only
  1436. <    integers.  You can #define several manifest constants, however,
  1437. ---
  1438. >    integers.  An alternative is to #define several macros with
  1439. >    symbolic names and distinct integer values, and implement
  1440.     conditionals on those.
  1441. ==========
  1442.     (Better yet, try to write code which is inherently insensitive
  1443. <    to type sizes.)
  1444. ---
  1445. >    to type sizes; see also question 1.1.)
  1446. ==========
  1447.     Other possible solutions are to use different macros (DEBUG1,
  1448. <    DEBUG2, etc.) depending on the number of arguments, to play
  1449. <    games with commas:
  1450. ---
  1451. >    DEBUG2, etc.) depending on the number of arguments, or to play
  1452. >    tricky games with commas:
  1453. ==========
  1454. <    It is often better to use a bona-fide function, which can take a
  1455. ---
  1456. >    Finally, you can always use a bona-fide function, which can take
  1457. ==========
  1458. <    At the time of this writing, the cost is $130.00 from ANSI or
  1459. ---
  1460. >    The last time I checked, the cost was $130.00 from ANSI or
  1461.     $400.50 from Global.  Copies of the original X3.159 (including
  1462. ==========
  1463. >    Public review drafts of C9X are available from ISO/IEC
  1464. >    JTC1/SC22/WG14's web site, http://www.dkuug.dk/JTC1/SC22/WG14/ .
  1465. ==========
  1466. < 11.2a: Where can I get information about updates to the Standard?
  1467. ---
  1468. > 11.2b: Where can I get information about updates to the Standard?
  1469. ==========
  1470. < A:    You can find some information at the web sites
  1471. <    http://www.lysator.liu.se/c/index.html and http://www.dmk.com/ .
  1472. ---
  1473. > A:    You can find information (including C9X drafts) at
  1474. >    the web sites http://www.lysator.liu.se/c/index.html,
  1475. >    http://www.dkuug.dk/JTC1/SC22/WG14/, and http://www.dmk.com/ .
  1476. ==========
  1477.   A:    You have mixed the new-style prototype declaration
  1478.     "extern int func(float);" with the old-style definition
  1479. <    "int func(x) float x;".  It is usually safe to mix the two
  1480. ---
  1481. >    "int func(x) float x;".  It is usually possible to mix the two
  1482.     styles (see question 11.4), but not in this case.
  1483. ==========
  1484.     (In this case, it would be clearest to change the old-style
  1485. <    definition to use double as well, as long as the address of that
  1486. <    parameter is not taken.)
  1487. ---
  1488. >    definition to use double as well, if possible.)
  1489. ==========
  1490. <    It may also be safer to avoid "narrow" (char, short int, and
  1491. ---
  1492. >    It is arguably much safer to avoid "narrow" (char, short int,
  1493.     and float) function arguments and return types altogether.
  1494. ==========
  1495. < 11.12: Can I declare main() as void, to shut off these annoying "main
  1496. ---
  1497. > 11.12b: Can I declare main() as void, to shut off these annoying "main
  1498. ==========
  1499. <    need to access the environment in ways beyind what the standard
  1500. ---
  1501. >    need to access the environment in ways beyond what the standard
  1502. ==========
  1503. <    Many books unaccountably use void main() in examples.  They're
  1504. ---
  1505. >    Many books unaccountably use void main() in examples, and assert
  1506. >    that it's correct.  They're wrong.
  1507. ==========
  1508. <    However, a few older, nonconforming systems may have problems
  1509. <    with one or the other form.  Also, a return from main() cannot
  1510. <    be expected to work if data local to main() might be needed
  1511. <    during cleanup; see also question 16.4.  (Finally, the two forms
  1512. ---
  1513. >    However, a return from main() cannot be expected to work if
  1514. >    data local to main() might be needed during cleanup; see also
  1515. >    question 16.4.  A few very old, nonconforming systems may once
  1516. >    have had problems with one or the other form.  (Finally, the two
  1517.     forms are obviously not equivalent in a recursive call to
  1518.     main().)
  1519. ==========
  1520. < 11.30: Why are some ANSI/ISO Standard library routines showing up as
  1521. ---
  1522. > 11.30: Why are some ANSI/ISO Standard library functions showing up as
  1523. ==========
  1524. A:    For one thing, the variable to hold getchar's return value
  1525.     must be an int.  getchar() can return all possible character
  1526. <    values, as well as EOF.  By passing getchar's return value
  1527. <    through a char, either a normal character might be
  1528. ---
  1529. >    as well as EOF.  By squeezing getchar's return value into a
  1530.     char, either a normal character might be misinterpreted as EOF,
  1531.     or the EOF might be altered (particularly if type char is
  1532.     unsigned) and so never seen.
  1533. ==========
  1534. < A:    In C, EOF is only indicated *after* an input routine has tried
  1535. <    to read, and has reached end-of-file.  (In other words, C's I/O
  1536. ---
  1537. > A:    In C, end-of-file is only indicated *after* an input routine has
  1538. >    tried to read, and failed.  (In other words, C's I/O is not like
  1539.     Pascal's.)  Usually, you should just check the return value of
  1540. ==========
  1541. <    return value of the input routine (fgets() in this case); often,
  1542. ---
  1543. >    the input routine (in this case, fgets() will return NULL on end-
  1544. >    of-file); often, you don't need to use feof() at all.
  1545. ==========
  1546.   A:    It's best to use an explicit fflush(stdout) whenever output
  1547. <    should definitely be visible.  Several mechanisms attempt to
  1548. ---
  1549. >    should definitely be visible (and especially if the text does
  1550. >    not end with \n).  Several mechanisms attempt to perform the
  1551. ==========
  1552.     \% can't work, because the backslash \ is the *compiler's*
  1553.     escape character, while here our problem is that the % is
  1554. <    printf's escape character.
  1555. ---
  1556. >    essentially printf's escape character.
  1557. ==========
  1558. < A:    printf("%*d", width, n) will do just what you want.
  1559. ---
  1560. > A:    printf("%*d", width, x) will do just what you want.
  1561. ==========
  1562. < A:    The routines in <locale.h> begin to provide some support for
  1563. ---
  1564. > A:    The functions in <locale.h> begin to provide some support for
  1565. ==========
  1566.   A:    You can't; an asterisk in a scanf() format string means to
  1567.     suppress assignment.  You may be able to use ANSI stringizing
  1568.     and string concatenation to accomplish about the same thing, or
  1569. <    to construct a scanf format string on-the-fly.
  1570. ---
  1571. >    you can construct the scanf format string at run time.
  1572. ==========
  1573. <    often useful; see also question 13.6.)  If you do use sscanf(),
  1574. ---
  1575. >    often useful; see also question 13.6.)  If you do use any scanf
  1576. >    variant, be sure to check the return value to make sure that the
  1577.     expected number of items were found.  Also, if you use %s, be
  1578. ==========
  1579.     When the format string being used with sprintf() is known and
  1580. <    relatively simple, you can usually predict a buffer size in an
  1581. ---
  1582. >    relatively simple, you can sometimes predict a buffer size in an
  1583.     ad-hoc way.  If the format consists of one or two %s's, you can
  1584. ==========
  1585. <    strlen() on the string(s) to be inserted.  The number of
  1586. ---
  1587. >    strlen() on the string(s) to be inserted.  For integers, the
  1588.     number of characters produced by %d is no more than
  1589. ==========
  1590.     There is no standard way to discard unread characters from a
  1591. <    stdio input stream, nor would such a way be sufficient, since
  1592. ---
  1593. >    stdio input stream, nor would such a way necessarily be
  1594.     sufficient, since unread characters can also accumulate in
  1595. ==========
  1596.   12.38: How can I read a binary data file properly?  I'm occasionally
  1597. <    seeing 0x0a and 0x0d values getting garbled, and it seems to hit
  1598. ---
  1599. >    seeing 0x0a and 0x0d values getting garbled, and I seem to hit
  1600.     EOF prematurely if the data contains the value 0x1a.
  1601. ==========
  1602. <    memcpy() is usually a more appropriate routine to use than
  1603. ---
  1604. >    memcpy() is usually a more appropriate function to use than
  1605. ==========
  1606. < A:    The only Standard routine available for this kind of
  1607. ---
  1608. > A:    The only Standard function available for this kind of
  1609. ==========
  1610.     The comparison function's arguments are expressed as "generic
  1611.     pointers," const void *.  They are converted back to what they
  1612. <    "really are" (char **) and dereferenced, yielding char *'s which
  1613. <    can be passed to strcmp().  (Under a pre-ANSI compiler, declare
  1614. <    the pointer parameters as char * instead of void *, and drop the
  1615. <    consts.)
  1616. ---
  1617. >    "really are" (pointers to pointers to char) and dereferenced,
  1618. >    yielding char *'s which can be passed to strcmp().
  1619. ==========
  1620.     (The conversions from generic pointers to struct mystruct
  1621.     pointers happen in the initializations sp1 = p1 and sp2 = p2;
  1622.     the compiler performs the conversions implicitly since p1 and p2
  1623. <    are void pointers.  Explicit casts, and char * pointers, would
  1624. <    be required under a pre-ANSI compiler.  See also question 7.7.)
  1625. ---
  1626. >    are void pointers.)
  1627. ==========
  1628.     If, on the other hand, you're sorting pointers to structures,
  1629.     you'll need indirection, as in question 13.8:
  1630. <    sp1 = *(struct mystruct **)p1 .
  1631. ---
  1632. >    sp1 = *(struct mystruct * const *)p1 .
  1633. ==========
  1634. < A:    Just use the time(), ctime(), and/or localtime() functions.
  1635. <    (These functions have been around for years, and are in the ANSI
  1636. <    standard.)  Here is a simple example:
  1637. ---
  1638. > A:    Just use the time(), ctime(), localtime() and/or strftime()
  1639. >    functions.  Here is a simple example:
  1640. ==========
  1641. < 13.13: I know that the library routine localtime() will convert a
  1642. ---
  1643. > 13.13: I know that the library function localtime() will convert a
  1644. ==========
  1645. < A:    ANSI C specifies a library routine, mktime(), which converts a
  1646. ---
  1647. > A:    ANSI C specifies a library function, mktime(), which converts a
  1648. ==========
  1649. <    the inverse of strftime().  Other popular routines are partime()
  1650. ---
  1651. >    the inverse of strftime().  Other popular functions are partime()
  1652. ==========
  1653.     Another approach to both problems is to use "Julian day"
  1654. <    numbers.  Implementations of Julian day routines can be found in
  1655. <    the file JULCAL10.ZIP from the Simtel/Oakland archives (see
  1656. ---
  1657. >    numbers".  Code for handling Julian day numbers can be found
  1658. >    in the Snippets collection (see question 18.15c), the
  1659. >    Simtel/Oakland archives (file JULCAL10.ZIP, see question 18.16),
  1660. ==========
  1661. < 13.24:    I'm trying to port this         A:    Those routines are variously
  1662. ---
  1663. > 13.24:    I'm trying to port this         A:    Those functions are variously
  1664. ==========
  1665. <    Contrariwise, if you're using an older system which is missing
  1666. <    the functions in the second column, you may be able to implement
  1667. <    them in terms of, or substitute, the functions in the first.
  1668. ==========
  1669.   A:    In general, a header file contains only declarations.  In some
  1670. <    cases (especially if the functions are nonstandard) you may have
  1671. <    to explicitly ask for the correct libraries to be searched when
  1672. ---
  1673. >    cases (especially if the functions are nonstandard) obtaining
  1674. >    the actual *definitions* may require explicitly asking for the
  1675.     correct libraries to be searched when you link the program.
  1676. ==========
  1677.   A:    That message is a quirk of the old Unix linkers.  You get an
  1678. <    error about _end being undefined only when other things are
  1679. ---
  1680. >    error about _end being undefined only when other symbols are
  1681.     undefined, too -- fix the others, and the error about _end will
  1682.     disappear.
  1683. ==========
  1684.   A:    Most computers use base 2 for floating-point numbers as well as
  1685. <    for integers.  In base 2, 1/1010 (that is, 1/10 decimal) is an
  1686. <    infinitely-repeating fraction: its binary representation is
  1687. <    0.0001100110011... .  Depending on how carefully your compiler's
  1688. ---
  1689. >    for integers.  In base 2, one divided by ten is an infinitely-
  1690. >    repeating fraction (0.0001100110011...), so fractions such as
  1691. >    3.1 (which look like they can be exactly represented in decimal)
  1692. >    cannot be represented exactly in binary.  Depending on how
  1693. ==========
  1694. <    routine to be careful with is atof(), which is declared in
  1695. ---
  1696. >    function to be careful with is atof(), which is declared in
  1697. ==========
  1698.     C has a pow() function, declared in <math.h>, although explicit
  1699. <    multiplication is often better for small positive integral
  1700. ---
  1701. >    multiplication is usually better for small positive integral
  1702.     exponents.
  1703. ==========
  1704. < A:    Ajay Shah maintains an index of free numerical software; it is
  1705. <    posted periodically, and archived in the comp.lang.c directory
  1706. <    at rtfm.mit.edu (see question 20.40).
  1707. ---
  1708. > A:    Ajay Shah has prepared a nice index of free numerical
  1709. >    software which has been archived pretty widely; one URL
  1710. >    is ftp://ftp.math.psu.edu/pub/FAQ/numcomp-free-c .
  1711. ==========
  1712.     It happens that Borland's heuristics for determining
  1713.     whether the program uses floating point are insufficient, and
  1714. <    the programmer must sometimes insert an extra, explicit call to
  1715. <    a floating-point library routine (such as sqrt(); any will do)
  1716. ---
  1717. >    the programmer must sometimes insert a dummy call to a floating-
  1718. >    point library function (such as sqrt(); any will do) to force
  1719.     loading of floating-point support.
  1720. ==========
  1721. <    Here is an error() routine which prints an error message,
  1722. ---
  1723. >    Here is an error() function which prints an error message,
  1724. ==========
  1725.     are predictable, you can pass an explicit count of the number of
  1726.     variable arguments (although it's usually a nuisance for the
  1727. <    caller to generate).
  1728. ---
  1729. >    caller to supply).
  1730. ==========
  1731.     (For analogous reasons, the last "fixed" argument, as handed to
  1732. <    va_start(), should not be widenable.)  See also questions 11.3
  1733. ---
  1734. >    va_start(), should not be widenable, either.)  See also
  1735. ==========
  1736. < 16.2a: I'm getting baffling syntax errors which make no sense at all,
  1737. ---
  1738. > 16.1b:  I'm getting baffling syntax errors which make no sense at all,
  1739. ==========
  1740. < 16.2b: Why isn't my procedure call working?  The compiler seems to skip
  1741. ---
  1742. > 16.1c: Why isn't my procedure call working?  The compiler seems to skip
  1743. ==========
  1744. >    C has only functions, and function calls always require
  1745. ---
  1746. <    C only has functions, and function calls always require
  1747.     parenthesized argument lists, even if empty.
  1748. ==========
  1749.   16.5:    This program runs perfectly on one machine, but I get weird
  1750. <    results on another.  Stranger still, adding or removing
  1751. <    debugging printouts changes the symptoms...
  1752. ---
  1753. >    results on another.  Stranger still, adding or removing a
  1754. >    debugging printout changes the symptoms...
  1755. ==========
  1756. <    A better option is to use a macro:
  1757. ---
  1758. >    Another option is to use a macro:
  1759.         #define Streq(s1, s2) (strcmp((s1), (s2)) == 0)
  1760. ==========
  1761. <    Opinions on code style, like those on religion, can be debated
  1762. <    endlessly.  Though good style is a worthy goal, and can usually
  1763. <    be recognized, it cannot be rigorously codified.  See also
  1764. ---
  1765. >    See also question 17.10.
  1766. ==========
  1767. <    Evidently it can be easier to remember to reverse the test than
  1768. <    it is to remember to type the doubled = sign.
  1769. ---
  1770. >    Evidently it can be easier for some people to remember to
  1771. >    reverse the test than to remember to type the doubled = sign.
  1772. >    (Of course, the trick only helps when comparing to a constant.)
  1773. ==========
  1774.   A:    Hungarian Notation is a naming convention, invented by Charles
  1775. <    Simonyi, which encodes things about a variable's type (and
  1776. ---
  1777. >    Simonyi, which encodes information about a variable's type (and
  1778.     perhaps its intended use) in its name.  It is well-loved in some
  1779. ==========
  1780. <        cs.washington.edu    pub/cstyle.tar.Z
  1781. ---
  1782. >        ftp.cs.washington.edu    pub/cstyle.tar.Z
  1783. ==========
  1784.     Programming Style_, _Plum Hall Programming Guidelines_, and _C
  1785. <    Style: Standards and Guidelines_; see the Bibliography.  (The
  1786. <    _Standards and Guidelines_ book is not in fact a style guide,
  1787. <    but a set of guidelines on selecting and creating style guides.)
  1788. ---
  1789. >    Style: Standards and Guidelines_; see the Bibliography.
  1790. ==========
  1791. <    a revision control or        RCS or SCCS
  1792. ---
  1793. >    a revision control or        CVS, RCS, or SCCS
  1794.     configuration management
  1795.     tool
  1796. ==========
  1797. <    a C declaration aid        see question 1.21
  1798. <    (cdecl)
  1799. ---
  1800. >    a C declaration aid        check volume 14 of
  1801. >    (cdecl)                comp.sources.unix (see
  1802. >                    question 18.16) and K&R2
  1803. ==========
  1804. <    See also questions 18.16 and 18.3.
  1805. ---
  1806. >    See also questions 18.3 and 18.16.
  1807. ==========
  1808.         Purify, from Pure Software, 1309 S. Mary Ave., Sunnyvale,
  1809.         CA 94087, USA, 800-224-7873, http://www.pure.com ,
  1810.         info-home@pure.com .
  1811. >        (I believe Pure was recently acquired by Rational.)
  1812. ==========
  1813. <    archive sites.  An MS-DOS port, djgpp, is also available; it can
  1814. <    be found at ftp.delorie.com in pub/djgpp, or at the various
  1815. <    SimTel mirrors (e.g. ftp.simtel.net in pub/simtelnet/gnu/djgpp;
  1816. <    ftp.coast.net in SimTel/vendors/djgpp).
  1817. ---
  1818. >    archive sites.  An MS-DOS port, djgpp, is also available;
  1819. >    see the djgpp home page at http://www.delorie.com/djgpp/ .
  1820. ==========
  1821. >    There are currently no viable shareware compilers for the
  1822. >    Macintosh.
  1823. ==========
  1824.     Tim Love's "C for Programmers" is available by ftp from svr-
  1825.     ftp.eng.cam.ac.uk in the misc directory.  An html version is at
  1826. <    http://club.eng.cam.ac.uk/help/tpl/languages/C/teaching_C/
  1827. ---
  1828. >    http://www-h.eng.cam.ac.uk/help/tpl/languages/C/teaching_C/
  1829.     teaching_C.html .
  1830. ==========
  1831.     On some Unix machines you can try typing "learn c" at the shell
  1832. <    prompt.
  1833. ---
  1834. >    prompt (but the lessons may be quite dated).
  1835. ==========
  1836.     Finally, the author of this FAQ list teaches a C class
  1837. <    and has begun putting its notes on the web; they are at
  1838. ---
  1839. >    and has placed its notes on the web; they are at
  1840.     http://www.eskimo.com/~scs/cclass/cclass.html .
  1841. ==========
  1842. <    [Disclaimer: I have not reviewed all of these tutorials, and I
  1843. <    have heard that at least one of them contains a number of
  1844. ---
  1845. >    [Disclaimer: I have not reviewed many of these tutorials, and
  1846. >    I gather that they tend to contain errors.  With the exception
  1847. ==========
  1848. <    This FAQ list's editor maintains a collection of previous
  1849. <    answers to this question, which is available upon request.
  1850. ---
  1851. >    This FAQ list's editor has a large collection of assorted
  1852. >    old recommendations which various people have posted; it
  1853. >    is available upon request.
  1854. ==========
  1855. > 18.13c: Where can I get a copy of the ANSI/ISO C Standard?
  1856. >
  1857. > A:    See question 11.2.
  1858. ==========
  1859. A:    The definitive grammar is of course the one in the ANSI
  1860.     standard; see question 11.2.  Another grammar (along with one
  1861.     for C++) by Jim Roskind is in pub/c++grammar1.1.tar.Z at
  1862. <    ics.uci.edu .  A fleshed-out, working instance of the ANSI
  1863. ---
  1864. >    ics.uci.edu (or perhaps ftp.ics.uci.edu, or perhaps
  1865. >    OLD/pub/c++grammar1.1.tar.Z), or at ftp.eskimo.com in
  1866. >    u/s/scs/roskind_grammar.Z .  A fleshed-out, working instance of
  1867. ==========
  1868. < 18.15a: Does anyone have a C compiler test suite I can use?
  1869. ---
  1870. > 18.15b: Does anyone have a C compiler test suite I can use?
  1871. ==========
  1872. < A:    Bob Stout's "SNIPPETS" collection is available from
  1873. ---
  1874. > A:    Bob Stout's popular "SNIPPETS" collection is available from
  1875. ==========
  1876.     are probably new indexing services springing up every day.  One
  1877. <    of the first was "archie": for any program or resource available
  1878. <    on the net, if you know its name, an archie server can usually
  1879. <    tell you which anonymous ftp sites have it.  Your system may
  1880. <    have an archie command, or you can send the mail message "help"
  1881. <    to archie@archie.cs.mcgill.ca for information.
  1882. ---
  1883. >    of the first was "archie", and of course there are a number of
  1884. >    high-profile commercial net indexing and searching services such
  1885. >    as Alta Vista, Excite, and Yahoo.
  1886. ==========
  1887. <    How can I print things in inverse video?
  1888. ---
  1889. >    How can I print text in color?
  1890. ==========
  1891.     using.  You will have to use a library such as termcap,
  1892.     terminfo, or curses, or some system-specific routines, to
  1893. <    perform these operations.
  1894. ---
  1895. >    perform these operations.  On MS-DOS systems, two functions
  1896. >    to look for are clrscr() and gotoxy().
  1897. ==========
  1898.     For clearing the screen, a halfway portable solution is to print
  1899.     a form-feed character ('\f'), which will cause some displays to
  1900. <    clear.  Even more portable might be to print enough newlines to
  1901. ---
  1902. >    clear.  Even more portable (albeit even more gunky) might be to
  1903.     print enough newlines to scroll everything away.
  1904. ==========
  1905. <    See any DOS programming guide for lists of keyboard codes.
  1906. ---
  1907. >    See any DOS programming guide for lists of keyboard scan codes.
  1908. ==========
  1909. <    Three possible test routines are stat(), access(), and fopen().
  1910. ---
  1911. >    Three possible test functions are stat(), access(), and fopen().
  1912. ==========
  1913.     an approximate answer.  You can fseek() to the end and then use
  1914. <    ftell(), or maybe try fstat(), but these tend to have problems:
  1915. ---
  1916. >    ftell(), or maybe try fstat(), but these tend to have the same
  1917. >    sorts of problems: fstat() is not portable, and generally tells
  1918.     you the same thing stat() tells you; ftell() is not guaranteed
  1919. ==========
  1920. <    count except for binary files.  Some systems provide routines
  1921. <    called filesize() or filelength(), but these are not portable,
  1922. <    either.
  1923. ---
  1924. >    to return a byte count except for binary files.  Some systems
  1925. >    provide functions called filesize() or filelength(), but these
  1926. >    are obviously not portable, either.
  1927. ==========
  1928. < 19.12a: How can I find the modification date and time of a file?
  1929. ---
  1930. > 19.12b: How can I find the modification date and time of a file?
  1931. ==========
  1932.     multiple links).  It is best to remember the names of files
  1933. <    yourself when you open them (perhaps with a wrapper function
  1934. ---
  1935. >    yourself as you open them (perhaps with a wrapper function
  1936. ==========
  1937. <    be passed through to fopen() (or any other routine) correctly,
  1938. ---
  1939. >    be passed through to fopen() (or any other function) correctly,
  1940. ==========
  1941. < A:    See if you can use the opendir() and readdir() routines, which
  1942. ---
  1943. > A:    See if you can use the opendir() and readdir() functions, which
  1944. ==========
  1945. < A:    Unix and some other systems provide a popen() routine, which
  1946. ---
  1947. > A:    Unix and some other systems provide a popen() function, which
  1948. ==========
  1949.     and the modified environment is generally passed on to child
  1950.     processes, but it is *not* propagated back to the parent
  1951. <    process.
  1952. ---
  1953. >    process.  Under MS-DOS, it's possible to manipulate the master
  1954. >    copy of the environment, but the required techniques are arcane.
  1955. >    (See an MS-DOS FAQ list.)
  1956. ==========
  1957. < 19.36: How can I read in an object file and jump to routines in it?
  1958. ---
  1959. > 19.36: How can I read in an object file and jump to locations in it?
  1960. ==========
  1961.     Of these, only clock() is part of the ANSI Standard.  The
  1962.     difference between two calls to clock() gives elapsed execution
  1963. <    time, and if CLOCKS_PER_SEC is greater than 1, the difference will
  1964. <    have subsecond resolution.  However, clock() gives elapsed
  1965. ---
  1966. >    time, and may even have subsecond resolution, if CLOCKS_PER_SEC
  1967. >    is greater than 1.  However, clock() gives elapsed processor time
  1968. ==========
  1969.     but resist this temptation if at all possible!  For one thing,
  1970. <    your carefully-calculated delay loops will stop working next
  1971. ---
  1972. >    your carefully-calculated delay loops will stop working properly
  1973.     next month when a faster processor comes out.  Perhaps worse, a
  1974. ==========
  1975. < A:    On many systems, you can define a routine matherr() which will
  1976. ---
  1977. > A:    On many systems, you can define a function matherr() which will
  1978. ==========
  1979. < 19.40b: How do I use BIOS calls?  How can I write ISR's?  How can I
  1980. <    create TSR's?
  1981. ---
  1982. > 19.40b: How do I...  Use BIOS calls?  Write ISR's?  Create TSR's?
  1983. ==========
  1984.     %x, etc.) and in the strtol() and strtoul() functions by the
  1985. <    third argument.  During *binary* I/O, however, the base again
  1986. ---
  1987. >    third argument.  If you need to output numeric strings in
  1988. >    arbitrary bases, you'll have to supply your own function to do
  1989. >    so (it will essentially be the inverse of strtol).  During
  1990. ==========
  1991.   20.12: What is the most efficient way to count the number of bits which
  1992. <    are set in a value?
  1993. ---
  1994. >    are set in an integer?
  1995. ==========
  1996. <    See also questions question 20.17.
  1997. ---
  1998. >    See also question 20.17.
  1999. ==========
  2000. <    Note also that // comments, as in C++, are not currently legal
  2001. ---
  2002. >    Note also that // comments, as in C++, are not yet legal in C,
  2003.     so it's not a good idea to use them in C programs (even if your
  2004. ==========
  2005.     cfortran.h, a C header file, simplifies C/FORTRAN interfacing on
  2006.     many popular machines.  It is available via anonymous ftp from
  2007. <    zebra.desy.de (131.169.2.244).
  2008. ---
  2009. >    zebra.desy.de or at http://www-zeus.desy.de/~burow .
  2010. ==========
  2011. <    (or some other data structure) to a a bounded number (the "hash
  2012. ---
  2013. <    (or some other data structure) to a bounded number (the "hash
  2014. ==========
  2015.   20.34: Here's a good puzzle: how do you write a program which produces
  2016. <    its own source code as its output?
  2017. ---
  2018. >    its own source code as output?
  2019. ==========
  2020. <    Here is a classic example (which is normally presented on one
  2021. ---
  2022. >    Here is a classic example (which ought to be presented on one
  2023.     line, although it will fix itself the first time it's run):
  2024. ==========
  2025.     newsgroups comp.answers and news.answers .  Several sites
  2026.     archive news.answers postings and other FAQ lists, including
  2027.     this one; two sites are rtfm.mit.edu (directories
  2028.     pub/usenet/news.answers/C-faq/ and pub/usenet/comp.lang.c/) and
  2029. <    ftp.uu.net (directory usenet/news.answers/C-faq/).  An archie
  2030. <    server (see question 18.16) should help you find others; ask it
  2031. <    to "find C-faq".  If you don't have ftp access, a mailserver at
  2032. ---
  2033. >    ftp.uu.net (directory usenet/news.answers/C-faq/).  If you don't
  2034. ==========
  2035. <    URL's pointing at all FAQ lists (these may also    allow topic
  2036. <    searching) are http://www.cis.ohio-state.edu/hypertext/faq/
  2037. <    usenet/FAQ-List.html and http://www.luth.se/wais/ .
  2038. ---
  2039. >    A comprehensive site which references all Usenet FAQ lists is
  2040. >    http://www.faqs.org/faqs/ .
  2041. ==========
  2042. < Americal National Standards Institute, _American National Standard for
  2043. ---
  2044. > American National Standards Institute, _American National Standard for
  2045. ==========
  2046. < Americal National Standards Institute, _Rationale for American National
  2047. ---
  2048. > American National Standards Institute, _Rationale for American National
  2049. ==========
  2050. < G.E.P. Box and Mervin E. Muller, "A Note on the Generation of Random
  2051. < Normal Deviates," _Annals of Mathematical Statistics_, Vol. 29 #2, June,
  2052. < 1958, pp. 610-611.
  2053. ==========
  2054. > International Organization for Standardization, WG14/N794 Working Draft
  2055. > (see questions 11.1 and 11.2b).  [C9X]
  2056. ==========
  2057.   Donald E. Knuth, _The Art of Computer Programming_.  Volume 1:
  2058.   _Fundamental Algorithms_, Second Edition, Addison-Wesley, 1973, ISBN 0-
  2059.   201-03809-9.  Volume 2: _Seminumerical Algorithms_, Second Edition,
  2060.   Addison-Wesley, 1981, ISBN 0-201-03822-6.  Volume 3: _Sorting and
  2061. < Searching_, Addison-Wesley, 1973, ISBN 0-201-03803-X.  [Knuth]
  2062. ---
  2063. > Searching_, Addison-Wesley, 1973, ISBN 0-201-03803-X.  (New editions
  2064. > are coming out!) [Knuth]
  2065. ==========
  2066. > G. Marsaglia and T.A. Bray, "A Convenient Method for Generating Normal
  2067. > Variables," _SIAM Review_, Vol. 6 #3, July, 1964.
  2068. ==========
  2069.   Robert Sedgewick, _Algorithms in C_, Addison-Wesley, 1990,
  2070. < ISBN 0-201-51425-7.
  2071. ---
  2072. > ISBN 0-201-51425-7.  (A new edition is being prepared;
  2073. > the first half is ISBN 0-201-31452-5.)
  2074. ==========
  2075. > Thanks to Jamshid Afshar, Lauri Alanko, David Anderson, Tanner Andrews,
  2076.   Sudheer Apte, Joseph Arceneaux, Randall Atkinson, Rick Beem, Peter
  2077.   Bennett, Wayne Berke, Dan Bernstein, Tanmoy Bhattacharya, John Bickers,
  2078.   Gary Blaine, Yuan Bo, Mark J. Bobak, Dave Boutcher, Alan Bowler, Michael
  2079. > Bresnahan, Walter Briscoe, Vincent Broman, Robert T. Brown, Stan Brown,
  2080.   John R. Buchan, Joe Buehler, Kimberley Burchett, Gordon Burditt, Scott
  2081.   Burkett, Burkhard Burow, Conor P. Cahill, D'Arcy J.M. Cain, Christopher
  2082.   Calabrese, Ian Cargill, Vinit Carpenter, Paul Carter, Mike Chambers,
  2083.   Billy Chambless, C. Ron Charlton, Franklin Chen, Jonathan Chen, Raymond
  2084. > Chen, Richard Cheung, Avinash Chopde, Steve Clamage, Ken Corbin, Dann
  2085. > Corbit, Ian Cottam, Russ Cox, Jonathan Coxhead, Lee Crawford, Nick
  2086.   Cropper, Steve Dahmer, Andrew Daviel, James Davies, John E. Davis, Ken
  2087.   Delong, Norm Diamond, Bob Dinse, Jeff Dunlop, Ray Dunn, Stephen M. Dunn,
  2088.   Michael J. Eager, Scott Ehrlich, Arno Eigenwillig, Yoav Eilat, Dave
  2089.   Eisen, Joe English, Bjorn Engsig, David Evans, Clive D.W. Feather,
  2090.   Dominic Feeley, Simao Ferraz, Chris Flatters, Rod Flores, Alexander
  2091.   Forst, Steve Fosdick, Jeff Francis, Ken Fuchs, Tom Gambill, Dave
  2092.   Gillespie, Samuel Goldstein, Tim Goodwin, Alasdair Grant, Ron Guilmette,
  2093. > Doug Gwyn, Michael Hafner, Darrel Hankerson, Tony Hansen, Douglas
  2094. > Wilhelm Harder, Elliotte Rusty Harold, Joe Harrington, Des Herriott,
  2095.   Guy Harris, John Hascall, Ger Hobbelt, Jos Horsmeier, Syed Zaeem Hosain,
  2096.   Blair Houghton, James C. Hu, Chin Huang, David Hurt, Einar Indridason,
  2097.   Vladimir Ivanovic, Jon Jagger, Ke Jin, Kirk Johnson, Larry Jones, Arjan
  2098.   Kenter, Bhaktha Keshavachar, James Kew, Darrell Kindred, Lawrence Kirby,
  2099. > Kin-ichi Kitano, Peter Klausler, John Kleinjans, Andrew Koenig, Tom
  2100.   Koenig, Adam Kolawa, Jukka Korpela, Ajoy Krishnan T, Jon Krom, Markus
  2101.   Kuhn, Deepak Kulkarni, Oliver Laumann, John Lauro, Felix Lee, Mike Lee,
  2102. > Timothy J. Lee, Tony Lee, Marty Leisner, Dave Lewis; Don Libes, Brian
  2103.   Liedtke, Philip Lijnzaad, Keith Lindsay, Yen-Wei Liu, Paul Long,
  2104.   Christopher Lott, Tim Love, Tim McDaniel, J. Scott McKellar, Kevin
  2105. > McMahon, Stuart MacMartin, John R. MacMillan, Robert S. Maier, Andrew
  2106. > Main, Bob Makowski, Evan Manning, Barry Margolin, George Marsaglia,
  2107.   George Matas, Brad Mears, Wayne Mery, De Mickey, Rich Miller, Roger
  2108.   Miller, Bill Mitchell, Mark Moraes, Darren Morby, Bernhard Muenzer,
  2109.   David Murphy, Walter Murray, Ralf Muschall, Ken Nakata, Todd Nathan,
  2110.   Taed Nelson, Landon Curt Noll, Tim Norman, Paul Nulsen, David O'Brien,
  2111. > Richard A. O'Keefe, Adam Kolawa, Keith Edward O'hara, James Ojaste, Max
  2112. > Okumoto, Hans Olsson, Bob Peck, Andrew Phillips, Christopher Phillips,
  2113.   Francois Pinard, Nick Pitfield, Wayne Pollock, Polver@aol.com, Dan Pop,
  2114.   Claudio Potenza, Lutz Prechelt, Lynn Pye, Kevin D. Quitt, Pat Rankin,
  2115.   Arjun Ray, Eric S. Raymond, Peter W. Richards, James Robinson, Eric
  2116.   Roode, Manfred Rosenboom, J. M. Rosenstock, Rick Rowe, Erkki Ruohtula,
  2117.   John Rushford, Kadda Sahnine, Tomohiko Sakamoto, Matthew Saltzman, Rich
  2118.   Salz, Chip Salzenberg, Matthew Sams, Paul Sand, DaviD W. Sanderson,
  2119.   Frank Sandy, Christopher Sawtell, Jonas Schlein, Paul Schlyter, Doug
  2120. > Schmidt, Rene Schmit, Russell Schulz, Dean Schulze, Jens Schweikhardt,
  2121.   Chris Sears, Peter Seebach, Patricia Shanahan, Aaron Sherman, Raymond
  2122. > Shwake, Nathan Sidwell, Peter da Silva, Joshua Simons, Ross Smith, Henri
  2123.   Socha, Leslie J. Somos, Henry Spencer, David Spuler, Frederic Stark,
  2124. > James Stern, Zalman Stern, Michael Sternberg, Geoff Stevens, Alan
  2125. > Stokes, Bob Stout, Dan Stubbs, Steve Sullivan, Melanie Summit, Erik
  2126.   Talvola, Dave Taylor, Clarke Thatcher, Wayne Throop, Chris Torek, Steve
  2127. > Traugott, Nikos Triantafillis, Ilya Tsindlekht, Andrew Tucker, Goran
  2128.   Uddeborg, Rodrigo Vanegas, Jim Van Zandt, Wietse Venema, Tom Verhoeff,
  2129.   Ed Vielmetti, Larry Virden, Chris Volpe, Mark Warren, Alan Watson, Kurt
  2130.   Watzka, Larry Weiss, Martin Weitzel, Howard West, Tom White, Freek
  2131.   Wiedijk, Tim Wilson, Dik T. Winter, Lars Wirzenius, Dave Wolverton,
  2132.   Mitch Wright, Conway Yee, Ozan S. Yigit, and Zhuo Zang, who have
  2133.   contributed, directly or indirectly, to this article.
  2134. ==========
  2135.   Thanks to Debbie Lafferty and Tom Stone at Addison-Wesley for
  2136. > encouragment, and permission to cross-pollinate this list with new text
  2137. ---
  2138. < encouragement, and permission to cross-pollinate this list with new text
  2139.   from the book.
  2140. ==========
  2141. < This article is Copyright 1990-1996 by Steve Summit.
  2142. ---
  2143. > This article is Copyright 1990-1999 by Steve Summit.
  2144. ==========
  2145. < Except as noted otherwise, the C code in this article is public domain
  2146. < and may be used without restriction.
  2147. ---
  2148. > With the exception of the examples by other, cited authors (i.e. in
  2149. > questions 20.31 and 20.35) the C code in this article is public domain
  2150. > and may be used without restriction.
  2151. ==========
  2152.  
  2153.                         Steve Summit
  2154.                         scs@eskimo.com
  2155.