home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / C-faq / abridged next >
Internet Message Format  |  2004-05-16  |  61KB

  1. From: scs@eskimo.com (Steve Summit)
  2. Newsgroups: comp.lang.c,comp.lang.c.moderated,comp.answers,news.answers
  3. Subject: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)
  4. Followup-To: poster
  5. Date: 15 May 2004 10:00:05 GMT
  6. Organization: better late than never
  7. Lines: 1949
  8. Approved: news-answers-request@MIT.Edu
  9. Expires: 3 Jun 2004 00:00:00 GMT
  10. Message-ID: <2004May15.0600.scs.0001@eskimo.com>
  11. Reply-To: scs@eskimo.com
  12. NNTP-Posting-Host: eskimo.com
  13. X-Trace: eskinews.eskimo.com 1084615205 4663 204.122.16.13 (15 May 2004 10:00:05 GMT)
  14. X-Complaints-To: abuse@eskimo.com
  15. NNTP-Posting-Date: 15 May 2004 10:00:05 GMT
  16. X-Last-Modified: February 7, 1999
  17. X-Archive-Name: C-faq/abridged
  18. X-Version: 3.5a
  19. X-URL: http://www.eskimo.com/~scs/C-faq/top.html
  20. X-PGP-Signature: Version: 2.6.2
  21.     iQCSAwUBMjhNk96sm4I1rmP1AQEF/QPndRyxOJtumiupKJiAkknSZsQr+8RTntjh
  22.     zx8054S9qgdEOgpx3QHea681LklR8g51w+k04fxFU9VeRNuRh6I9yTWG1JjPZRpf
  23.     NkcthDa8uNQ0JtWYWef2Jk7/sc2A0L88fHBpnG2epI5av2FwcqO3JKGNR4YkRCb6
  24.     MM80Pcg=
  25.     =amQx
  26. Originator: scs@eskimo.com
  27. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!4.24.21.218.MISMATCH!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!news-out.visi.com!green.octanews.net!news-out.octanews.net!news.glorb.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!nntp.giganews.com.MISMATCH!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!news-peer1.sprintlink.net!news-sj-1.sprintlink.net!news-west.sprintlink.net!news-in-west1.sprintlink.net!news.sprintlink.net!news.eskimo.com!eskimo.com!s
  28. cs
  29. Xref: senator-bedfellow.mit.edu comp.lang.c:689225 comp.lang.c.moderated:26758 comp.answers:57143 news.answers:271296
  30.  
  31. Archive-name: C-faq/abridged
  32. Comp-lang-c-archive-name: C-FAQ-list.abridged
  33. URL: http://www.eskimo.com/~scs/C-faq/top.html
  34.  
  35. [Last modified February 7, 1999 by scs.]
  36.  
  37. This article is Copyright 1990-1999 by Steve Summit.  Content from the
  38. book _C Programming FAQs: Frequently Asked Questions_ is made available
  39. here by permission of the author and the publisher as a service to the
  40. community.  It is intended to complement the use of the published text
  41. and is protected by international copyright laws.  The content is made
  42. available here and may be accessed freely for personal use but may not
  43. be republished without permission.
  44.  
  45. This article contains minimal answers to the comp.lang.c frequently-
  46. asked questions list.  More detailed explanations and references can be
  47. found in the long version (posted on the first of each month, or see
  48. question 20.40 for availability), and in the web version at http://www.eskimo.com/~scs/C-faq/top.html
  49. , and in the book _C Programming FAQs: Frequently Asked Questions_
  50. (Addison-Wesley, 1996, ISBN 0-201-84519-9). 
  51.  
  52. Section 1. Declarations and Initializations
  53.  
  54. 1.1:    How do you decide which integer type to use?
  55.  
  56. A:    If you might need large values (tens of thousands), use long.
  57.     Otherwise, if space is very important, use short.  Otherwise,
  58.     use int.
  59.  
  60. 1.4:    What should the 64-bit type on a machine that can support it?
  61.  
  62. A:    C9X specifies long long.
  63.  
  64. 1.7:    What's the best way to declare and define global variables?
  65.  
  66. A:    The best arrangement is to place each definition in some
  67.     relevant .c file, with an external declaration in a header file.
  68.  
  69. 1.11:    What does extern mean in a function declaration?
  70.  
  71. A:    Nothing, really; the keyword extern is optional here.
  72.  
  73. 1.12:    What's the auto keyword good for?
  74.  
  75. A:    Nothing.
  76.  
  77. 1.14:    I can't seem to define a linked list node which contains a
  78.     pointer to itself.
  79.  
  80. A:    Structures in C can certainly contain pointers to themselves;
  81.     the discussion and example in section 6.5 of K&R make this
  82.     clear.  Problems arise if an attempt is made to define (and use)
  83.     a typedef in the midst of such a declaration; avoid this.
  84.  
  85. 1.21:    How do I declare an array of N pointers to functions returning
  86.     pointers to functions returning pointers to characters?
  87.  
  88. A:    char *(*(*a[N])())();
  89.     Using a chain of typedefs, or the cdecl program, makes these
  90.     declarations easier.
  91.  
  92. 1.22:    How can I declare a function that returns a pointer to a
  93.     function of its own type?
  94.  
  95. A:    You can't quite do it directly.  Use a cast, or wrap a struct
  96.     around the pointer and return that.
  97.  
  98. 1.25:    My compiler is complaining about an invalid redeclaration of a
  99.     function, but I only define it once.
  100.  
  101. A:    Calling an undeclared function declares it implicitly as
  102.     returning int.
  103.  
  104. 1.25b:    What's the right declaration for main()?
  105.  
  106. A:    See questions 11.12a to 11.15.
  107.  
  108. 1.30:    What am I allowed to assume about the initial values
  109.     of variables which are not explicitly initialized?
  110.  
  111. A:    Uninitialized variables with "static" duration start out as 0,
  112.     as if the programmer had initialized them.  Variables with
  113.     "automatic" duration, and dynamically-allocated memory, start
  114.     out containing garbage (with the exception of calloc).
  115.  
  116. 1.31:    Why can't I initialize a local array with a string?
  117.  
  118. A:    Perhaps you have a pre-ANSI compiler.
  119.  
  120. 1.31b:    What's wrong with "char *p = malloc(10);" ?
  121.  
  122. A:    Function calls are not allowed in initializers for global or
  123.     static variables.
  124.  
  125. 1.32:    What is the difference between char a[] = "string"; and
  126.     char *p = "string"; ?
  127.  
  128. A:    The first declares an initialized and modifiable array; the
  129.     second declares a pointer initialized to a not-necessarily-
  130.     modifiable constant string.
  131.  
  132. 1.34:    How do I initialize a pointer to a function?
  133.  
  134. A:    Use something like "extern int func(); int (*fp)() = func;" .
  135.  
  136.  
  137. Section 2. Structures, Unions, and Enumerations
  138.  
  139. 2.1:    What's the difference between struct x1 { ... }; and
  140.     typedef struct { ... } x2; ?
  141.  
  142. A:    The first structure is named by a tag, the second by a typedef
  143.     name.
  144.  
  145. 2.2:    Why doesn't "struct x { ... }; x thestruct;" work?
  146.  
  147. A:    C is not C++.
  148.  
  149. 2.3:    Can a structure contain a pointer to itself?
  150.  
  151. A:    See question 1.14.
  152.  
  153. 2.4:    What's the best way of implementing opaque (abstract) data types
  154.     in C?
  155.  
  156. A:    One good way is to use structure pointers which point to
  157.     structure types which are not publicly defined.
  158.  
  159. 2.6:    I came across some code that declared a structure with the last
  160.     member an array of one element, and then did some tricky
  161.     allocation to make it act like the array had several elements.
  162.     Is this legal or portable?
  163.  
  164. A:    An official interpretation has deemed that it is not strictly
  165.     conforming with the C Standard.
  166.  
  167. 2.7:    I heard that structures could be assigned to variables and
  168.     passed to and from functions, but K&R1 says not.
  169.  
  170. A:    These operations are supported by all modern compilers.
  171.  
  172. 2.8:    Is there a way to compare structures automatically?
  173.  
  174. A:    No.
  175.  
  176. 2.10:    Can I pass constant values to functions which accept structure
  177.     arguments?
  178.  
  179. A:    Not yet.  As of this writing, C has no way of generating
  180.     anonymous structure values.
  181.  
  182. 2.11:    How can I read/write structures from/to data files?
  183.  
  184. A:    It is relatively straightforward to use fread and fwrite.
  185.  
  186. 2.12:    How can I turn off structure padding?
  187.  
  188. A:    There is no standard method.
  189.  
  190. 2.13:    Why does sizeof report a larger size than I expect for a
  191.     structure type?
  192.  
  193. A:    The alignment of arrays of structures must be preserved.
  194.  
  195. 2.14:    How can I determine the byte offset of a field within a
  196.     structure?
  197.  
  198. A:    ANSI C defines the offsetof() macro, which should be used if
  199.     available.
  200.  
  201. 2.15:    How can I access structure fields by name at run time?
  202.  
  203. A:    Build a table of names and offsets, using the offsetof() macro.
  204.  
  205. 2.18:    I have a program which works correctly, but dumps core after it
  206.     finishes.  Why?
  207.  
  208. A:    Check to see if a structure type declaration just before main()
  209.     is missing its trailing semicolon, causing main() to be declared
  210.     as returning a structure.  See also questions 10.9 and 16.4.
  211.  
  212. 2.20:    Can I initialize unions?
  213.  
  214. A:    The current C Standard allows an initializer for the first-named
  215.     member.
  216.  
  217. 2.22:    What is the difference between an enumeration and a set of
  218.     preprocessor #defines?
  219.  
  220. A:    At the present time, there is little difference.  The C Standard
  221.     states that enumerations are compatible with integral types.
  222.  
  223. 2.24:    Is there an easy way to print enumeration values symbolically?
  224.  
  225. A:    No.
  226.  
  227.  
  228. Section 3. Expressions
  229.  
  230. 3.1:    Why doesn't the code "a[i] = i++;" work?
  231.  
  232. A:    The variable i is both referenced and modified in the same
  233.     expression.
  234.  
  235. 3.2:    Under my compiler, the code "int i = 7;
  236.     printf("%d\n", i++ * i++);" prints 49.  Regardless of the order
  237.     of evaluation, shouldn't it print 56?
  238.  
  239. A:    The operations implied by the postincrement and postdecrement
  240.     operators ++ and -- are performed at some time after the
  241.     operand's former values are yielded and before the end of the
  242.     expression, but not necessarily immediately after, or before
  243.     other parts of the expression are evaluated.
  244.  
  245. 3.3:    What should the code "int i = 3; i = i++;" do?
  246.  
  247. A:    The expression is undefined.
  248.  
  249. 3.3b:    Here's a slick expression: "a ^= b ^= a ^= b".  It swaps a and b
  250.     without using a temporary.
  251.  
  252. A:    Not portably; its behavior is undefined.
  253.  
  254. 3.4:    Don't precedence and parentheses dictate order of evaluation?
  255.  
  256. A:    Operator precedence and explicit parentheses impose only a
  257.     partial ordering on the evaluation of an expression, which does
  258.     not generally include the order of side effects.
  259.  
  260. 3.5:    But what about the && and || operators?
  261.  
  262. A:    There is a special exception for those operators: left-to-right
  263.     evaluation is guaranteed.
  264.  
  265. 3.8:    What's a "sequence point"?
  266.  
  267. A:    A point (at the end of a full expression, or at the ||, &&, ?:,
  268.     or comma operators, or just before a function call) at which all
  269.     side effects are guaranteed to be complete.
  270.  
  271. 3.9:    So given a[i] = i++; we don't know which cell of a[] gets
  272.     written to, but i does get incremented by one, right?
  273.  
  274. A:    *No*.  Once an expression or program becomes undefined, *all*
  275.     aspects of it become undefined.
  276.  
  277. 3.12:    If I'm not using the value of the expression, should I use i++
  278.     or ++i to increment a variable?
  279.  
  280. A:    Since the two forms differ only in the value yielded, they are
  281.     entirely equivalent when only their side effect is needed.
  282.  
  283. 3.14:    Why doesn't the code "int a = 1000, b = 1000;
  284.     long int c = a * b;" work?
  285.  
  286. A:    You must manually cast one of the operands to (long).
  287.  
  288. 3.16:    Can I use ?: on the left-hand side of an assignment expression?
  289.  
  290. A:    No.
  291.  
  292.  
  293. Section 4. Pointers
  294.  
  295. 4.2:    What's wrong with "char *p; *p = malloc(10);"?
  296.  
  297. A:    The pointer you declared is p, not *p.
  298.  
  299. 4.3:    Does *p++ increment p, or what it points to?
  300.  
  301. A:    *p++ increments p.  To increment the value pointed to by p, use
  302.     (*p)++ .
  303.  
  304. 4.5:    I want to use a char * pointer to step over some ints.  Why
  305.     doesn't "((int *)p)++;" work?
  306.  
  307. A:    In C, a cast operator is a conversion operator, and by
  308.     definition it yields an rvalue, which cannot be assigned to, or
  309.     incremented with ++.
  310.  
  311. 4.8:    I have a function which accepts, and is supposed to initialize,
  312.     a pointer, but the pointer in the caller remains unchanged.
  313.  
  314. A:    The called function probably altered only the passed copy of the
  315.     pointer.
  316.  
  317. 4.9:    Can I use a void ** pointer as a parameter so that a function
  318.     can accept a generic pointer by reference?
  319.  
  320. A:    Not portably.
  321.  
  322. 4.10:    I have a function which accepts a pointer to an int.  How can I
  323.     pass a constant like 5 to it?
  324.  
  325. A:    You will have to declare a temporary variable.
  326.  
  327. 4.11:    Does C even have "pass by reference"?
  328.  
  329. A:    Not really, though it can be simulated.
  330.  
  331. 4.12:    I've seen different methods used for calling functions via
  332.     pointers.
  333.  
  334. A:    The extra parentheses and explicit * are now officially
  335.     optional, although some older implementations require them.
  336.  
  337.  
  338. Section 5. Null Pointers
  339.  
  340. 5.1:    What is this infamous null pointer, anyway?
  341.  
  342. A:    For each pointer type, there is a special value -- the "null
  343.     pointer" -- which is distinguishable from all other pointer
  344.     values and which is not the address of any object or function.
  345.  
  346. 5.2:    How do I get a null pointer in my programs?
  347.  
  348. A:    A constant 0 in a pointer context is converted into a null
  349.     pointer at compile time.  A "pointer context" is an
  350.     initialization, assignment, or comparison with one side a
  351.     variable or expression of pointer type, and (in ANSI standard C)
  352.     a function argument which has a prototype in scope declaring a
  353.     certain parameter as being of pointer type.  In other contexts
  354.     (function arguments without prototypes, or in the variable part
  355.     of variadic function calls) a constant 0 with an appropriate
  356.     explicit cast is required.
  357.  
  358. 5.3:    Is the abbreviated pointer comparison "if(p)" to test for non-
  359.     null pointers valid?
  360.  
  361. A:    Yes.  The construction "if(p)" works, regardless of the internal
  362.     representation of null pointers, because the compiler
  363.     essentially rewrites it as "if(p != 0)" and goes on to convert 0
  364.     into the correct null pointer.
  365.  
  366. 5.4:    What is NULL and how is it #defined?
  367.  
  368. A:    NULL is simply a preprocessor macro, #defined as 0 (or
  369.     ((void *)0)), which is used (as a stylistic convention, in
  370.     preference to unadorned 0's) to generate null pointers.
  371.  
  372. 5.5:    How should NULL be defined on a machine which uses a nonzero bit
  373.     pattern as the internal representation of a null pointer?
  374.  
  375. A:    The same as on any other machine: as 0.  (The compiler makes the
  376.     translation, upon seeing a 0, not the preprocessor; see also
  377.     question 5.4.)
  378.  
  379. 5.6:    If NULL were defined as "((char *)0)," wouldn't that make
  380.     function calls which pass an uncast NULL work?
  381.  
  382. A:    Not in general.  The complication is that there are machines
  383.     which use different internal representations for pointers to
  384.     different types of data.  A cast is still required to tell the
  385.     compiler which kind of null pointer is required, since it may be
  386.     different from (char *)0.
  387.  
  388. 5.9:    If NULL and 0 are equivalent as null pointer constants, which
  389.     should I use?
  390.  
  391. A:    Either; the distinction is entirely stylistic.
  392.  
  393. 5.10:    But wouldn't it be better to use NULL, in case the value of NULL
  394.     changes?
  395.  
  396. A:    No.  NULL is a constant zero, so a constant zero is equally
  397.     sufficient.
  398.  
  399. 5.12:    I use the preprocessor macro "#define Nullptr(type) (type *)0"
  400.     to help me build null pointers of the correct type.
  401.  
  402. A:    This trick, though valid, does not buy much.
  403.  
  404. 5.13:    This is strange.  NULL is guaranteed to be 0, but the null
  405.     pointer is not?
  406.  
  407. A:    A "null pointer" is a language concept whose particular internal
  408.     value does not matter.  A null pointer is requested in source
  409.     code with the character "0".  "NULL" is a preprocessor macro,
  410.     which is always #defined as 0 (or ((void *)0)).
  411.  
  412. 5.14:    Why is there so much confusion surrounding null pointers?
  413.  
  414. A:    The fact that null pointers are represented both in source code,
  415.     and internally to most machines, as zero invites unwarranted
  416.     assumptions.  The use of a preprocessor macro (NULL) may seem to
  417.     suggest that the value could change some day, or on some weird
  418.     machine.
  419.  
  420. 5.15:    I'm confused.  I just can't understand all this null pointer
  421.     stuff.
  422.  
  423. A:    A simple rule is, "Always use `0' or `NULL' for null pointers,
  424.     and always cast them when they are used as arguments in function
  425.     calls."
  426.  
  427. 5.16:    Given all the confusion surrounding null pointers, wouldn't it
  428.     be easier simply to require them to be represented internally by
  429.     zeroes?
  430.  
  431. A:    Such a requirement would accomplish little.
  432.  
  433. 5.17:    Seriously, have any actual machines really used nonzero null
  434.     pointers?
  435.  
  436. A:    Machines manufactured by Prime, Honeywell-Bull, and CDC, as well
  437.     as Symbolics Lisp Machines, have done so.
  438.  
  439. 5.20:    What does a run-time "null pointer assignment" error mean?
  440.  
  441. A:    It means that you've written, via a null pointer, to an invalid
  442.     location.  (See also question 16.8.)
  443.  
  444.  
  445. Section 6. Arrays and Pointers
  446.  
  447. 6.1:    I had the definition char a[6] in one source file, and in
  448.     another I declared extern char *a.  Why didn't it work?
  449.  
  450. A:    The declaration extern char *a simply does not match the actual
  451.     definition.  Use extern char a[].
  452.  
  453. 6.2:    But I heard that char a[] was identical to char *a.
  454.  
  455. A:    Not at all.  Arrays are not pointers.  A reference like x[3]
  456.     generates different code depending on whether x is an array or a
  457.     pointer.
  458.  
  459. 6.3:    So what is meant by the "equivalence of pointers and arrays" in
  460.     C?
  461.  
  462. A:    An lvalue of type array-of-T which appears in an expression
  463.     decays into a pointer to its first element; the type of the
  464.     resultant pointer is pointer-to-T.  So for an array a and
  465.     pointer p, you can say "p = a;" and then p[3] and a[3] will
  466.     access the same element.
  467.  
  468. 6.4:    Why are array and pointer declarations interchangeable as
  469.     function formal parameters?
  470.  
  471. A:    It's supposed to be a convenience.
  472.  
  473. 6.7:    How can an array be an lvalue, if you can't assign to it?
  474.  
  475. A:    An array is not a "modifiable lvalue."
  476.  
  477. 6.8:    What is the real difference between arrays and pointers?
  478.  
  479. A:    Arrays automatically allocate space which is fixed in size and
  480.     location; pointers are dynamic.
  481.  
  482. 6.9:    Someone explained to me that arrays were really just constant
  483.     pointers.
  484.  
  485. A:    An array name is "constant" in that it cannot be assigned to,
  486.     but an array is *not* a pointer.
  487.  
  488. 6.11:    I came across some "joke" code containing the "expression"
  489.     5["abcdef"] .  How can this be legal C?
  490.  
  491. A:    Yes, array subscripting is commutative in C.  The array
  492.     subscripting operation a[e] is defined as being identical to
  493.     *((a)+(e)).
  494.  
  495. 6.12:    What's the difference between array and &array?
  496.  
  497. A:    The type.
  498.  
  499. 6.13:    How do I declare a pointer to an array?
  500.  
  501. A:    Usually, you don't want to.  Consider using a pointer to one of
  502.     the array's elements instead.
  503.  
  504. 6.14:    How can I set an array's size at run time?
  505.  
  506. A:    It's straightforward to use malloc() and a pointer.
  507.  
  508. 6.15:    How can I declare local arrays of a size matching a passed-in
  509.     array?
  510.  
  511. A:    Until recently, you couldn't; array dimensions had to be compile-
  512.     time constants.  C9X will fix this.
  513.  
  514. 6.16:    How can I dynamically allocate a multidimensional array?
  515.  
  516. A:    The traditional solution is to allocate an array of pointers,
  517.     and then initialize each pointer to a dynamically-allocated
  518.     "row."  See the full list for code samples.
  519.  
  520. 6.17:    Can I simulate a non-0-based array with a pointer?
  521.  
  522. A:    Not if the pointer points outside of the block of memory it is
  523.     intended to access.
  524.  
  525. 6.18:    My compiler complained when I passed a two-dimensional array to
  526.     a function expecting a pointer to a pointer.
  527.  
  528. A:    The rule by which arrays decay into pointers is not applied
  529.     recursively.  An array of arrays (i.e. a two-dimensional array
  530.     in C) decays into a pointer to an array, not a pointer to a
  531.     pointer.
  532.  
  533. 6.19:    How do I write functions which accept two-dimensional arrays
  534.     when the width is not known at compile time?
  535.  
  536. A:    It's not always particularly easy.
  537.  
  538. 6.20:    How can I use statically- and dynamically-allocated
  539.     multidimensional arrays interchangeably when passing them to
  540.     functions?
  541.  
  542. A:    There is no single perfect method, but see the full list for
  543.     some ideas.
  544.  
  545. 6.21:    Why doesn't sizeof properly report the size of an array which is
  546.     a parameter to a function?
  547.  
  548. A:    The sizeof operator reports the size of the pointer parameter
  549.     which the function actually receives.
  550.  
  551.  
  552. Section 7. Memory Allocation
  553.  
  554. 7.1:    Why doesn't the code "char *answer; gets(answer);" work?
  555.  
  556. A:    The pointer variable answer has not been set to point to any
  557.     valid storage.  The simplest way to correct this fragment is to
  558.     use a local array, instead of a pointer.
  559.  
  560. 7.2:    I can't get strcat() to work.  I tried "char *s3 =
  561.     strcat(s1, s2);" but I got strange results.
  562.  
  563. A:    Again, the main problem here is that space for the concatenated
  564.     result is not properly allocated.
  565.  
  566. 7.3:    But the man page for strcat() says that it takes two char *'s as
  567.     arguments.  How am I supposed to know to allocate things?
  568.  
  569. A:    In general, when using pointers you *always* have to consider
  570.     memory allocation, if only to make sure that the compiler is
  571.     doing it for you.
  572.  
  573. 7.3b:    I just tried the code "char *p; strcpy(p, "abc");" and it
  574.     worked.  Why didn't it crash?
  575.  
  576. A:    You got "lucky".
  577.  
  578. 7.3c:    How much memory does a pointer variable allocate?
  579.  
  580. A:    Only enough memory to hold the pointer itself, not any memory
  581.     for the pointer to point to.
  582.  
  583. 7.5a:    I have a function that is supposed to return a string, but when
  584.     it returns to its caller, the returned string is garbage.
  585.  
  586. A:    Make sure that the pointed-to memory is properly (i.e. not
  587.     locally) allocated.
  588.  
  589. 7.5b:    So what's the right way to return a string?
  590.  
  591. A:    Return a pointer to a statically-allocated buffer, a buffer
  592.     passed in by the caller, or memory obtained with malloc().
  593.  
  594. 7.6:    Why am I getting "warning: assignment of pointer from integer
  595.     lacks a cast" for calls to malloc()?
  596.  
  597. A:    Have you #included <stdlib.h>?
  598.  
  599. 7.7:    Why does some code carefully cast the values returned by malloc
  600.     to the pointer type being allocated?
  601.  
  602. A:    Before ANSI/ISO C, these casts were required to silence certain
  603.     warnings.
  604.  
  605. 7.8:    Why does so much code leave out the multiplication by
  606.     sizeof(char) when allocating strings?
  607.  
  608. A:    Because sizeof(char) is, by definition, exactly 1.
  609.  
  610. 7.14:    I've heard that some operating systems don't actually allocate
  611.     malloc'ed memory until the program tries to use it.  Is this
  612.     legal?
  613.  
  614. A:    It's hard to say.
  615.  
  616. 7.16:    I'm allocating a large array for some numeric work, but malloc()
  617.     is acting strangely.
  618.  
  619. A:    Make sure the number you're trying to pass to malloc() isn't
  620.     bigger than a size_t can hold.
  621.  
  622. 7.17:    I've got 8 meg of memory in my PC.  Why can I only seem to
  623.     malloc 640K or so?
  624.  
  625. A:    Under the segmented architecture of PC compatibles, it can be
  626.     difficult to use more than 640K with any degree of transparency.
  627.     See also question 19.23.
  628.  
  629. 7.19:    My program is crashing, apparently somewhere down inside malloc.
  630.  
  631. A:    Make sure you aren't using more memory than you malloc'ed,
  632.     especially for strings (which need strlen(str) + 1 bytes).
  633.  
  634. 7.20:    You can't use dynamically-allocated memory after you free it,
  635.     can you?
  636.  
  637. A:    No.  Some early documentation implied otherwise, but the claim
  638.     is no longer valid.
  639.  
  640. 7.21:    Why isn't a pointer null after calling free()?
  641.  
  642. A:    C's pass-by-value semantics mean that called functions can never
  643.     permanently change the values of their arguments.
  644.  
  645. 7.22:    When I call malloc() to allocate memory for a local pointer, do
  646.     I have to explicitly free() it?
  647.  
  648. A:    Yes.
  649.  
  650. 7.23:    When I free a dynamically-allocated structure containing
  651.     pointers, do I also have to free each subsidiary pointer?
  652.  
  653. A:    Yes.
  654.  
  655. 7.24:    Must I free allocated memory before the program exits?
  656.  
  657. A:    You shouldn't have to.
  658.  
  659. 7.25:    Why doesn't my program's memory usage go down when I free
  660.     memory?
  661.  
  662. A:    Most implementations of malloc/free do not return freed memory
  663.     to the operating system.
  664.  
  665. 7.26:    How does free() know how many bytes to free?
  666.  
  667. A:    The malloc/free implementation remembers the size of each block
  668.     as it is allocated.
  669.  
  670. 7.27:    So can I query the malloc package to find out how big an
  671.     allocated block is?
  672.  
  673. A:    Not portably.
  674.  
  675. 7.30:    Is it legal to pass a null pointer as the first argument to
  676.     realloc()?
  677.  
  678. A:    ANSI C sanctions this usage, although several earlier
  679.     implementations do not support it.
  680.  
  681. 7.31:    What's the difference between calloc() and malloc()?
  682.  
  683. A:    calloc() takes two arguments, and initializes the allocated
  684.     memory to all-bits-0.
  685.  
  686. 7.32:    What is alloca() and why is its use discouraged?
  687.  
  688. A:    alloca() allocates memory which is automatically freed when the
  689.     function which called alloca() returns.  alloca() cannot be
  690.     written portably, is difficult to implement on machines without
  691.     a stack, and fails under certain conditions if implemented
  692.     simply.
  693.  
  694.  
  695. Section 8. Characters and Strings
  696.  
  697. 8.1:    Why doesn't "strcat(string, '!');" work?
  698.  
  699. A:    strcat() concatenates *strings*, not characters.
  700.  
  701. 8.2:    Why won't the test if(string == "value") correctly compare
  702.     string against the value?
  703.  
  704. A:    It's comparing pointers.  To compare two strings, use strcmp().
  705.  
  706. 8.3:    Why can't I assign strings to character arrays?
  707.  
  708. A:    Strings are arrays, and you can't assign arrays directly.  Use
  709.     strcpy() instead.
  710.  
  711. 8.6:    How can I get the numeric (character set) value corresponding to
  712.     a character?
  713.  
  714. A:    In C, if you have the character, you have its value.
  715.  
  716. 8.9:    Why is sizeof('a') not 1?
  717.  
  718. A:    Character constants in C are of type int.
  719.  
  720.  
  721. Section 9. Boolean Expressions and Variables
  722.  
  723. 9.1:    What is the right type to use for Boolean values in C?
  724.  
  725. A:    There's no one right answer; see the full list for some
  726.     discussion.
  727.  
  728. 9.2:    What if a built-in logical or relational operator "returns"
  729.     something other than 1?
  730.  
  731. A:    When a Boolean value is generated by a built-in operator, it is
  732.     guaranteed to be 1 or 0.  (This is *not* true for some library
  733.     routines such as isalpha.)
  734.  
  735. 9.3:    Is if(p), where p is a pointer, valid?
  736.  
  737. A:    Yes.  See question 5.3.
  738.  
  739.  
  740. Section 10. C Preprocessor
  741.  
  742. 10.2:    I've got some cute preprocessor macros that let me write C code
  743.     that looks more like Pascal.  What do y'all think?
  744.  
  745. A:    Bleah.
  746.  
  747. 10.3:    How can I write a generic macro to swap two values?
  748.  
  749. A:    There is no good answer to this question.  The best all-around
  750.     solution is probably to forget about using a macro.
  751.  
  752. 10.4:    What's the best way to write a multi-statement macro?
  753.  
  754. A:    #define Func() do {stmt1; stmt2; ... } while(0)    /* (no trailing ;) */
  755.  
  756. 10.6:    What are .h files and what should I put in them?
  757.  
  758. A:    Header files (also called ".h files") should generally contain
  759.     common declarations and macro, structure, and typedef
  760.     definitions, but not variable or function definitions.
  761.  
  762. 10.7:    Is it acceptable for one header file to #include another?
  763.  
  764. A:    It's a question of style, and thus receives considerable debate.
  765.  
  766. 10.8a:    What's the difference between #include <> and #include "" ?
  767.  
  768. A:    Roughly speaking, the <> syntax is for Standard headers and ""
  769.     is for project headers.
  770.  
  771. 10.8b:    What are the complete rules for header file searching?
  772.  
  773. A:    The exact behavior is implementation-defined; see the full list
  774.     for some discussion.
  775.  
  776. 10.9:    I'm getting strange syntax errors on the very first declaration
  777.     in a file, but it looks fine.
  778.  
  779. A:    Perhaps there's a missing semicolon at the end of the last
  780.     declaration in the last header file you're #including.
  781.  
  782. 10.10b:    I'm #including the header file for a function, but the linker
  783.     keeps saying it's undefined.
  784.  
  785. A:    See question 13.25.
  786.  
  787. 10.11:    Where can I get a copy of a missing header file?
  788.  
  789. A:    Contact your vendor, or see question 18.16 or the full list.
  790.  
  791. 10.12:    How can I construct preprocessor #if expressions which compare
  792.     strings?
  793.  
  794. A:    You can't do it directly; try #defining several manifest
  795.     constants and implementing conditionals on those.
  796.  
  797. 10.13:    Does the sizeof operator work in preprocessor #if directives?
  798.  
  799. A:    No.
  800.  
  801. 10.14:    Can I use an #ifdef in a #define line, to define something two
  802.     different ways?
  803.  
  804. A:    No.
  805.  
  806. 10.15:    Is there anything like an #ifdef for typedefs?
  807.  
  808. A:    Unfortunately, no.
  809.  
  810. 10.16:    How can I use a preprocessor #if expression to detect
  811.     endianness?
  812.  
  813. A:    You probably can't.
  814.  
  815. 10.18:    How can I preprocess some code to remove selected conditional
  816.     compilations, without preprocessing everything?
  817.  
  818. A:    Look for a program called unifdef, rmifdef, or scpp.
  819.  
  820. 10.19:    How can I list all of the predefined identifiers?
  821.  
  822. A:    If the compiler documentation is unhelpful, try extracting
  823.     printable strings from the compiler or preprocessor executable.
  824.  
  825. 10.20:    I have some old code that tries to construct identifiers with a
  826.     macro like "#define Paste(a, b) a/**/b", but it doesn't work any
  827.     more.
  828.  
  829. A:    Try the ANSI token-pasting operator ##.
  830.  
  831. 10.22:    What does the message "warning: macro replacement within a
  832.     string literal" mean?
  833.  
  834. A:    See question 11.18.
  835.  
  836. 10.23-4: I'm having trouble using macro arguments inside string
  837.     literals, using the `#' operator.
  838.  
  839. A:    See questions 11.17 and 11.18.
  840.  
  841. 10.25:    I've got this tricky preprocessing I want to do and I can't
  842.     figure out a way to do it.
  843.  
  844. A:    Consider writing your own little special-purpose preprocessing
  845.     tool, instead.
  846.  
  847. 10.26:    How can I write a macro which takes a variable number of
  848.     arguments?
  849.  
  850. A:    Here is one popular trick.  Note that the parentheses around
  851.     printf's argument list are in the macro call, not the
  852.     definition.
  853.  
  854.         #define DEBUG(args) (printf("DEBUG: "), printf args)
  855.  
  856.         if(n != 0) DEBUG(("n is %d\n", n));
  857.  
  858.  
  859. Section 11. ANSI/ISO Standard C
  860.  
  861. 11.1:    What is the "ANSI C Standard?"
  862.  
  863. A:    In 1983, the American National Standards Institute (ANSI)
  864.     commissioned a committee to standardize the C language.  Their
  865.     work was ratified as ANS X3.159-1989, and has since been adopted
  866.     as ISO/IEC 9899:1990, and later amended.
  867.  
  868. 11.2:    How can I get a copy of the Standard?
  869.  
  870. A:    Copies are available from ANSI in New York, or from Global
  871.     Engineering Documents in Englewood, CO, or from any national
  872.     standards body, or from ISO in Geneva, or republished within one
  873.     or more books.  See the unabridged list for details.
  874.  
  875. 11.2b:    Where can I get information about updates to the Standard?
  876.  
  877. A:    See the full list for pointers.
  878.  
  879. 11.3:    My ANSI compiler is complaining about prototype mismatches for
  880.     parameters declared float.
  881.  
  882. A:    You have mixed the new-style prototype declaration
  883.     "extern int func(float);" with the old-style definition
  884.     "int func(x) float x;".  "Narrow" types are treated differently
  885.     according to which syntax is used.  This problem can be fixed by
  886.     avoiding narrow types, or by using either new-style (prototype)
  887.     or old-style syntax consistently.
  888.  
  889. 11.4:    Can you mix old-style and new-style function syntax?
  890.  
  891. A:    Doing so is currently legal, for most argument types
  892.     (see question 11.3).
  893.  
  894. 11.5:    Why does the declaration "extern int f(struct x *p);" give me a
  895.     warning message?
  896.  
  897. A:    A structure declared (or even mentioned) for the first time
  898.     within a prototype cannot be compatible with other structures
  899.     declared in the same source file.
  900.  
  901. 11.8:    Why can't I use const values in initializers and array
  902.     dimensions?
  903.  
  904. A:    The value of a const-qualified object is *not* a constant
  905.     expression in the full sense of the term.
  906.  
  907. 11.9:    What's the difference between "const char *p" and
  908.     "char * const p"?
  909.  
  910. A:    The former declares a pointer to a constant character; the
  911.     latter declares a constant pointer to a character.
  912.  
  913. 11.10:    Why can't I pass a char ** to a function which expects a
  914.     const char **?
  915.  
  916. A:    The rule which permits slight mismatches in qualified pointer
  917.     assignments is not applied recursively.
  918.  
  919. 11.12a:    What's the correct declaration of main()?
  920.  
  921. A:    int main(int argc, char *argv[]) .
  922.  
  923. 11.12b:    Can I declare main() as void, to shut off these annoying "main
  924.     returns no value" messages?
  925.  
  926. A:    No.
  927.  
  928. 11.13:    But what about main's third argument, envp?
  929.  
  930. A:    It's a non-standard (though common) extension.
  931.  
  932. 11.14:    I believe that declaring void main() can't fail, since I'm
  933.     calling exit() instead of returning.
  934.  
  935. A:    It doesn't matter whether main() returns or not, the problem is
  936.     that its caller may not even be able to *call* it correctly.
  937.  
  938. 11.15:    The book I've been using always uses void main().
  939.  
  940. A:    It's wrong.
  941.  
  942. 11.16:    Is exit(status) truly equivalent to returning the same status
  943.     from main()?
  944.  
  945. A:    Yes and no.  (See the full list for details.)
  946.  
  947. 11.17:    How do I get the ANSI "stringizing" preprocessing operator `#'
  948.     to stringize the macro's value instead of its name?
  949.  
  950. A:    You can use a two-step #definition to force a macro to be
  951.     expanded as well as stringized.
  952.  
  953. 11.18:    What does the message "warning: macro replacement within a
  954.     string literal" mean?
  955.  
  956. A:    Some pre-ANSI compilers/preprocessors expanded macro parameters
  957.     even inside string literals and character constants.
  958.  
  959. 11.19:    I'm getting strange syntax errors inside lines I've #ifdeffed
  960.     out.
  961.  
  962. A:    Under ANSI C, #ifdeffed-out text must still consist of "valid
  963.     preprocessing tokens."  This means that there must be no
  964.     newlines inside quotes, and no unterminated comments or quotes
  965.     (i.e. no single apostrophes).
  966.  
  967. 11.20:    What are #pragmas ?
  968.  
  969. A:    The #pragma directive provides a single, well-defined "escape
  970.     hatch" which can be used for extensions.
  971.  
  972. 11.21:    What does "#pragma once" mean?
  973.  
  974. A:    It is an extension implemented by some preprocessors to help
  975.     make header files idempotent.
  976.  
  977. 11.22:    Is char a[3] = "abc"; legal?
  978.  
  979. A:    Yes, in ANSI C.
  980.  
  981. 11.24:    Why can't I perform arithmetic on a void * pointer?
  982.  
  983. A:    The compiler doesn't know the size of the pointed-to objects.
  984.  
  985. 11.25:    What's the difference between memcpy() and memmove()?
  986.  
  987. A:    memmove() offers guaranteed behavior if the source and
  988.     destination arguments overlap.
  989.  
  990. 11.26:    What should malloc(0) do?
  991.  
  992. A:    The behavior is implementation-defined.
  993.  
  994. 11.27:    Why does the ANSI Standard not guarantee more than six case-
  995.     insensitive characters of external identifier significance?
  996.  
  997. A:    The problem is older linkers which cannot be forced (by mere
  998.     words in a Standard) to upgrade.
  999.  
  1000. 11.29:    My compiler is rejecting the simplest possible test programs,
  1001.     with all kinds of syntax errors.
  1002.  
  1003. A:    Perhaps it is a pre-ANSI compiler.
  1004.  
  1005. 11.30:    Why are some ANSI/ISO Standard library functions showing up as
  1006.     undefined, even though I've got an ANSI compiler?
  1007.  
  1008. A:    Perhaps you don't have ANSI-compatible headers and libraries.
  1009.  
  1010. 11.31:    Does anyone have a tool for converting old-style C programs to
  1011.     ANSI C, or for automatically generating prototypes?
  1012.  
  1013. A:    See the full list for details.
  1014.  
  1015. 11.32:    Why won't frobozz-cc, which claims to be ANSI compliant, accept
  1016.     this code?
  1017.  
  1018. A:    Are you sure that the code being rejected doesn't rely on some
  1019.     non-Standard extension?
  1020.  
  1021. 11.33:    What's the difference between implementation-defined,
  1022.     unspecified, and undefined behavior?
  1023.  
  1024. A:    If you're writing portable code, ignore the distinctions.
  1025.     Otherwise, see the full list.
  1026.  
  1027. 11.34:    I'm appalled that the ANSI Standard leaves so many issues
  1028.     undefined.
  1029.  
  1030. A:    In most of these cases, the Standard is simply codifying
  1031.     existing practice.
  1032.  
  1033. 11.35:    I just tried some allegedly-undefined code on an ANSI-conforming
  1034.     compiler, and got the results I expected.
  1035.  
  1036. A:    A compiler may do anything it likes when faced with undefined
  1037.     behavior, including doing what you expect.
  1038.  
  1039.  
  1040. Section 12. Stdio
  1041.  
  1042. 12.1:    What's wrong with the code "char c; while((c = getchar()) !=
  1043.     EOF) ..."?
  1044.  
  1045. A:    The variable to hold getchar's return value must be an int.
  1046.  
  1047. 12.2:    Why won't the code "while(!feof(infp)) {
  1048.     fgets(buf, MAXLINE, infp); fputs(buf, outfp); }" work?
  1049.  
  1050. A:    EOF is only indicated *after* an input routine fails.
  1051.  
  1052. 12.4:    My program's prompts and intermediate output don't always show
  1053.     up on the screen.
  1054.  
  1055. A:    It's best to use an explicit fflush(stdout) whenever output
  1056.     should definitely be visible.
  1057.  
  1058. 12.5:    How can I read one character at a time, without waiting for the
  1059.     RETURN key?
  1060.  
  1061. A:    See question 19.1.
  1062.  
  1063. 12.6:    How can I print a '%' character with printf?
  1064.  
  1065. A:    "%%".
  1066.  
  1067. 12.9:    How can printf() use %f for type double, if scanf() requires
  1068.     %lf?
  1069.  
  1070. A:    C's "default argument promotions" mean that values of type float
  1071.     are promoted to double.
  1072.  
  1073. 12.9b:    What printf format should I use for a typedef when I don't know
  1074.     the underlying type?
  1075.  
  1076. A:    Use a cast to convert the value to a known type, then use the
  1077.     printf format matching that type.
  1078.  
  1079. 12.10:    How can I implement a variable field width with printf?
  1080.  
  1081. A:    Use printf("%*d", width, x).
  1082.  
  1083. 12.11:    How can I print numbers with commas separating the thousands?
  1084.  
  1085. A:    There is no standard routine (but see <locale.h>).
  1086.  
  1087. 12.12:    Why doesn't the call scanf("%d", i) work?
  1088.  
  1089. A:    The arguments you pass to scanf() must always be pointers.
  1090.  
  1091. 12.13:    Why doesn't the code "double d; scanf("%f", &d);" work?
  1092.  
  1093. A:    Unlike printf(), scanf() uses %lf for double, and %f for float.
  1094.  
  1095. 12.15:    How can I specify a variable width in a scanf() format string?
  1096.  
  1097. A:    You can't.
  1098.  
  1099. 12.17:    When I read numbers from the keyboard with scanf "%d\n", it
  1100.     seems to hang until I type one extra line of input.
  1101.  
  1102. A:    Try using "%d" instead of "%d\n".
  1103.  
  1104. 12.18:    I'm reading a number with scanf %d and then a string with
  1105.     gets(), but the compiler seems to be skipping the call to
  1106.     gets()!
  1107.  
  1108. A:    scanf() and gets() do not work well together.
  1109.  
  1110. 12.19:    I'm re-prompting the user if scanf() fails, but sometimes it
  1111.     seems to go into an infinite loop.
  1112.  
  1113. A:    scanf() tends to "jam" on bad input since it does not discard
  1114.     it.
  1115.  
  1116. 12.20:    Why does everyone say not to use scanf()?  What should I use
  1117.     instead?
  1118.  
  1119. A:    scanf() has a number of problems.  Usually, it's easier to read
  1120.     entire lines and then interpret them.
  1121.  
  1122. 12.21:    How can I tell how much destination buffer space I'll need for
  1123.     an arbitrary sprintf call?  How can I avoid overflowing the
  1124.     destination buffer with sprintf()?
  1125.  
  1126. A:    Use the new snprintf() function, if you can.
  1127.  
  1128. 12.23:    Why does everyone say not to use gets()?
  1129.  
  1130. A:    It cannot be prevented from overflowing the input buffer.
  1131.  
  1132. 12.24:    Why does errno contain ENOTTY after a call to printf()?
  1133.  
  1134. A:    Don't worry about it.  It is only meaningful for a program to
  1135.     inspect the contents of errno after an error has been reported.
  1136.  
  1137. 12.25:    What's the difference between fgetpos/fsetpos and ftell/fseek?
  1138.  
  1139. A:    fgetpos() and fsetpos() use a special typedef which may allow
  1140.     them to work with larger files than ftell() and fseek().
  1141.  
  1142. 12.26:    Will fflush(stdin) flush unread characters from the standard
  1143.     input stream?
  1144.  
  1145. A:    No.
  1146.  
  1147. 12.30:    I'm trying to update a file in place, by using fopen mode "r+",
  1148.     but it's not working.
  1149.  
  1150. A:    Be sure to call fseek between reading and writing.
  1151.  
  1152. 12.33:    How can I redirect stdin or stdout from within a program?
  1153.  
  1154. A:    Use freopen().
  1155.  
  1156. 12.34:    Once I've used freopen(), how can I get the original stream
  1157.     back?
  1158.  
  1159. A:    There isn't a good way.  Try avoiding freopen.
  1160.  
  1161. 12.36b:    How can I arrange to have output go two places at once?
  1162.  
  1163. A:    You could write your own printf variant which printed everything
  1164.     twice.  See question 15.5.
  1165.  
  1166. 12.38:    How can I read a binary data file properly?
  1167.  
  1168. A:    Be sure to specify "rb" mode when calling fopen().
  1169.  
  1170.  
  1171. Section 13. Library Functions
  1172.  
  1173. 13.1:    How can I convert numbers to strings?
  1174.  
  1175. A:    Just use sprintf().
  1176.  
  1177. 13.2:    Why does strncpy() not always write a '\0'?
  1178.  
  1179. A:    For mildly-interesting historical reasons.
  1180.  
  1181. 13.5:    Why do some versions of toupper() act strangely if given an
  1182.     upper-case letter?
  1183.  
  1184. A:    Older versions of toupper() and tolower() did not always work as
  1185.     expected in this regard.
  1186.  
  1187. 13.6:    How can I split up a string into whitespace-separated fields?
  1188.  
  1189. A:    Try strtok().
  1190.  
  1191. 13.7:    I need some code to do regular expression and wildcard matching.
  1192.  
  1193. A:    regexp libraries abound; see the full list for details.
  1194.  
  1195. 13.8:    I'm trying to sort an array of strings with qsort(), using
  1196.     strcmp() as the comparison function, but it's not working.
  1197.  
  1198. A:    You'll have to write a "helper" comparison function which takes
  1199.     two generic pointer arguments, converts them to char **, and
  1200.     dereferences them, yielding char *'s which can be usefully
  1201.     compared.
  1202.  
  1203. 13.9:    Now I'm trying to sort an array of structures, but the compiler
  1204.     is complaining that the function is of the wrong type for
  1205.     qsort().
  1206.  
  1207. A:    The comparison function must be declared as accepting "generic
  1208.     pointers" (const void *) which it then converts to structure
  1209.     pointers.
  1210.  
  1211. 13.10:    How can I sort a linked list?
  1212.  
  1213. A:    Algorithms like insertion sort and merge sort work well, or you
  1214.     can keep the list in order as you build it.
  1215.  
  1216. 13.11:    How can I sort more data than will fit in memory?
  1217.  
  1218. A:    You want an "external sort"; see the full list for details.
  1219.  
  1220. 13.12:    How can I get the time of day in a C program?
  1221.  
  1222. A:    Just use the time(), ctime(), localtime() and/or strftime()
  1223.     functions.
  1224.  
  1225. 13.13:    How can I convert a struct tm or a string into a time_t?
  1226.  
  1227. A:    The ANSI mktime() function converts a struct tm to a time_t.  No
  1228.     standard routine exists to parse strings.
  1229.  
  1230. 13.14:    How can I perform calendar manipulations?
  1231.  
  1232. A:    The ANSI/ISO Standard C mktime() and difftime() functions
  1233.     provide some support for both problems.
  1234.  
  1235. 13.14b:    Does C have any Year 2000 problems?
  1236.  
  1237. A:    No, although poorly-written C programs do.  Make sure you know
  1238.     that tm_year holds the value of the year minus 1900.
  1239.  
  1240. 13.15:    I need a random number generator.
  1241.  
  1242. A:    The Standard C library has one: rand().
  1243.  
  1244. 13.16:    How can I get random integers in a certain range?
  1245.  
  1246. A:    One method is something like
  1247.  
  1248.         (int)((double)rand() / ((double)RAND_MAX + 1) * N)
  1249.  
  1250. 13.17:    Each time I run my program, I get the same sequence of numbers
  1251.     back from rand().
  1252.  
  1253. A:    You can call srand() to seed the pseudo-random number generator
  1254.     with a truly random initial value.
  1255.  
  1256. 13.18:    I need a random true/false value, so I'm just taking rand() % 2,
  1257.     but it's alternating 0, 1, 0, 1, 0...
  1258.  
  1259. A:    Try using the higher-order bits: see question 13.16.
  1260.  
  1261. 13.20:    How can I generate random numbers with a normal or Gaussian
  1262.     distribution?
  1263.  
  1264. A:    See the longer versions of this list for ideas.
  1265.  
  1266. 13.24:    I'm trying to port this old program.  Why do I get "undefined
  1267.     external" errors for some library functions?
  1268.  
  1269. A:    Some semistandard functions have been renamed or replaced over
  1270.     the years; see the full list for details.
  1271.  
  1272. 13.25:    I get errors due to library functions being undefined even
  1273.     though I #include the right header files.
  1274.  
  1275. A:    You may have to explicitly ask for the correct libraries to be
  1276.     searched.
  1277.  
  1278. 13.26:    I'm still getting errors due to library functions being
  1279.     undefined, even though I'm requesting the right libraries.
  1280.  
  1281. A:    Library search order is significant; usually, you must search
  1282.     the libraries last.
  1283.  
  1284. 13.28:    What does it mean when the linker says that _end is undefined?
  1285.  
  1286. A:    You generally get that message only when other symbols are
  1287.     undefined, too.
  1288.  
  1289.  
  1290. Section 14. Floating Point
  1291.  
  1292. 14.1:    When I set a float variable to 3.1, why is printf printing it as
  1293.     3.0999999?
  1294.  
  1295. A:    Most computers use base 2 for floating-point numbers, and many
  1296.     fractions (including 0.1 decimal) are not exactly representable
  1297.     in base 2.
  1298.  
  1299. 14.2:    Why is sqrt(144.) giving me crazy numbers?
  1300.  
  1301. A:    Make sure that you have #included <math.h>, and correctly
  1302.     declared other functions returning double.
  1303.  
  1304. 14.3:    I keep getting "undefined: sin" compilation errors.
  1305.  
  1306. A:    Make sure you're actually linking with the math library.
  1307.  
  1308. 14.4:    My floating-point calculations are acting strangely and giving
  1309.     me different answers on different machines.
  1310.  
  1311. A:    First, see question 14.2 above.  If the problem isn't that
  1312.     simple, see the full list for a brief explanation, or any good
  1313.     programming book for a better one.
  1314.  
  1315. 14.5:    What's a good way to check for "close enough" floating-point
  1316.     equality?
  1317.  
  1318. A:    The best way is to use an accuracy threshold which is relative
  1319.     to the magnitude of the numbers being compared.
  1320.  
  1321. 14.6:    How do I round numbers?
  1322.  
  1323. A:    For positive numbers, try (int)(x + 0.5) .
  1324.  
  1325. 14.7:    Where is C's exponentiation operator?
  1326.  
  1327. A:    Try using the pow() function.
  1328.  
  1329. 14.8:    The predefined constant M_PI seems to be missing from <math.h>.
  1330.  
  1331. A:    That constant is not standard.
  1332.  
  1333. 14.9:    How do I test for IEEE NaN and other special values?
  1334.  
  1335. A:    There is not yet a portable way, but see the full list for
  1336.     ideas.
  1337.  
  1338. 14.11:    What's a good way to implement complex numbers in C?
  1339.  
  1340. A:    It is straightforward to define a simple structure and some
  1341.     arithmetic functions to manipulate them.
  1342.  
  1343. 14.12:    I'm looking for some mathematical library code.
  1344.  
  1345. A:    See Ajay Shah's index of free numerical software at
  1346.     ftp://ftp.math.psu.edu/pub/FAQ/numcomp-free-c .
  1347.  
  1348. 14.13:    I'm having trouble with a Turbo C program which crashes and says
  1349.     something like "floating point formats not linked."
  1350.  
  1351. A:    You may have to insert a dummy call to a floating-point library
  1352.     function to force loading of floating-point support.
  1353.  
  1354.  
  1355. Section 15. Variable-Length Argument Lists
  1356.  
  1357. 15.1:    I heard that you have to #include <stdio.h> before calling
  1358.     printf().  Why?
  1359.  
  1360. A:    So that a proper prototype for printf() will be in scope.
  1361.  
  1362. 15.2:    How can %f be used for both float and double arguments in
  1363.     printf()?
  1364.  
  1365. A:    In variable-length argument lists, types char and short int are
  1366.     promoted to int, and float is promoted to double.
  1367.  
  1368. 15.3:    Why don't function prototypes guard against mismatches in
  1369.     printf's arguments?
  1370.  
  1371. A:    Function prototypes do not provide any information about the
  1372.     number and types of variable arguments.
  1373.  
  1374. 15.4:    How can I write a function that takes a variable number of
  1375.     arguments?
  1376.  
  1377. A:    Use the <stdarg.h> header.
  1378.  
  1379. 15.5:    How can I write a function that takes a format string and a
  1380.     variable number of arguments, like printf(), and passes them to
  1381.     printf() to do most of the work?
  1382.  
  1383. A:    Use vprintf(), vfprintf(), or vsprintf().
  1384.  
  1385. 15.6:    How can I write a function analogous to scanf(), that calls
  1386.     scanf() to do most of the work?
  1387.  
  1388. A:    C9X will support vscanf().
  1389.  
  1390. 15.7:    I have a pre-ANSI compiler, without <stdarg.h>.  What can I do?
  1391.  
  1392. A:    There's an older header, <varargs.h>, which offers about the
  1393.     same functionality.
  1394.  
  1395. 15.8:    How can I discover how many arguments a function was actually
  1396.     called with?
  1397.  
  1398. A:    Any function which takes a variable number of arguments must be
  1399.     able to determine *from the arguments' values* how many of them
  1400.     there are.
  1401.  
  1402. 15.9:    My compiler isn't letting me declare a function that accepts
  1403.     *only* variable arguments.
  1404.  
  1405. A:    Standard C requires at least one fixed argument.
  1406.  
  1407. 15.10:    Why isn't "va_arg(argp, float)" working?
  1408.  
  1409. A:    Because the "default argument promotions" apply in variable-
  1410.     length argument lists, you should always use
  1411.     va_arg(argp, double).
  1412.  
  1413. 15.11:    I can't get va_arg() to pull in an argument of type pointer-to-
  1414.     function.
  1415.  
  1416. A:    Use a typedef.
  1417.  
  1418. 15.12:    How can I write a function which takes a variable number of
  1419.     arguments and passes them to some other function ?
  1420.  
  1421. A:    In general, you cannot.
  1422.  
  1423. 15.13:    How can I call a function with an argument list built up at run
  1424.     time?
  1425.  
  1426. A:    You can't.
  1427.  
  1428.  
  1429. Section 16. Strange Problems
  1430.  
  1431. 16.1b:    I'm getting baffling syntax errors which make no sense at all,
  1432.     and it seems like large chunks of my program aren't being
  1433.     compiled.
  1434.  
  1435. A:    Check for unclosed comments or mismatched preprocessing
  1436.     directives.
  1437.  
  1438. 16.1c:    Why isn't my procedure call working?
  1439.  
  1440. A:    Function calls always require parenthesized argument lists.
  1441.  
  1442. 16.3:    This program crashes before it even runs!
  1443.  
  1444. A:    Look for very large, local arrays.
  1445.     (See also questions 11.12b, 16.4, 16.5, and 18.4.)
  1446.  
  1447. 16.4:    I have a program that seems to run correctly, but then crashes
  1448.     as it's exiting.
  1449.  
  1450. A:    See the full list for ideas.
  1451.  
  1452. 16.5:    This program runs perfectly on one machine, but I get weird
  1453.     results on another.
  1454.  
  1455. A:    See the full list for a brief list of possibilities.
  1456.  
  1457. 16.6:    Why does the code "char *p = "hello, world!"; p[0] = 'H';"
  1458.     crash?
  1459.  
  1460. A:    String literals are not modifiable, except (in effect) when they
  1461.     are used as array initializers.
  1462.  
  1463. 16.8:    What does "Segmentation violation" mean?
  1464.  
  1465. A:    It generally means that your program tried to access memory it
  1466.     shouldn't have, invariably as a result of stack corruption or
  1467.     improper pointer use.
  1468.  
  1469.  
  1470. Section 17. Style
  1471.  
  1472. 17.1:    What's the best style for code layout in C?
  1473.  
  1474. A:    There is no one "best style," but see the full list for a few
  1475.     suggestions.
  1476.  
  1477. 17.3:    Is the code "if(!strcmp(s1, s2))" good style?
  1478.  
  1479. A:    Not particularly.
  1480.  
  1481. 17.4:    Why do some people write if(0 == x) instead of if(x == 0)?
  1482.  
  1483. A:    It's a trick to guard against the common error of writing
  1484.     if(x = 0) .
  1485.  
  1486. 17.5:    I came across some code that puts a (void) cast before each call
  1487.     to printf().  Why?
  1488.  
  1489. A:    To suppress warnings about otherwise discarded return values.
  1490.  
  1491. 17.8:    What is "Hungarian Notation"?
  1492.  
  1493. A:    It's a naming convention which encodes information about a
  1494.     variable's type in its name.
  1495.  
  1496. 17.9:    Where can I get the "Indian Hill Style Guide" and other coding
  1497.     standards?
  1498.  
  1499. A:    See the unabridged list.
  1500.  
  1501. 17.10:    Some people say that goto's are evil and that I should never use
  1502.     them.  Isn't that a bit extreme?
  1503.  
  1504. A:    Yes.  Absolute rules are an imperfect approach to good
  1505.     programming style.
  1506.  
  1507.  
  1508. Section 18. Tools and Resources
  1509.  
  1510. 18.1:    I'm looking for C development tools (cross-reference generators,
  1511.     code beautifiers, etc.).
  1512.  
  1513. A:    See the full list for a few names.
  1514.  
  1515. 18.2:    How can I track down these pesky malloc problems?
  1516.  
  1517. A:    See the full list for a list of tools.
  1518.  
  1519. 18.3:    What's a free or cheap C compiler I can use?
  1520.  
  1521. A:    See the full list for a brief catalog.
  1522.  
  1523. 18.4:    I just typed in this program, and it's acting strangely.  Can
  1524.     you see anything wrong with it?
  1525.  
  1526. A:    See if you can run lint first.
  1527.  
  1528. 18.5:    How can I shut off the "warning: possible pointer alignment
  1529.     problem" message which lint gives me for each call to malloc()?
  1530.  
  1531. A:    It may be easier simply to ignore the message, perhaps in an
  1532.     automated way with grep -v.
  1533.  
  1534. 18.7:    Where can I get an ANSI-compatible lint?
  1535.  
  1536. A:    See the unabridged list for two commercial products.
  1537.  
  1538. 18.8:    Don't ANSI function prototypes render lint obsolete?
  1539.  
  1540. A:    No.  A good compiler may match most of lint's diagnostics; few
  1541.     provide all.
  1542.  
  1543. 18.9:    Are there any C tutorials or other resources on the net?
  1544.  
  1545. A:    There are several of them.
  1546.  
  1547. 18.10:    What's a good book for learning C?
  1548.  
  1549. A:    There are far too many books on C to list here; the full list
  1550.     contains a few pointers.
  1551.  
  1552. 18.13:    Where can I find the sources of the standard C libraries?
  1553.  
  1554. A:    Several possibilites are listed in the full list.
  1555.  
  1556. 18.13b:    Is there an on-line C reference manual?
  1557.  
  1558. A:    Two possibilities are
  1559.     http://www.cs.man.ac.uk/standard_c/_index.html and
  1560.     http://www.dinkumware.com/htm_cl/index.html .
  1561.  
  1562. 18.13c:    Where can I get a copy of the ANSI/ISO C Standard?
  1563.  
  1564. A:    See question 11.2.
  1565.  
  1566. 18.14:    I need code to parse and evaluate expressions.
  1567.  
  1568. A:    Several available packages are mentioned in the full list.
  1569.  
  1570. 18.15:    Where can I get a BNF or YACC grammar for C?
  1571.  
  1572. A:    See the ANSI Standard, or the unabridged list.
  1573.  
  1574. 18.15b:    Does anyone have a C compiler test suite I can use?
  1575.  
  1576. A:    See the full list for several sources.
  1577.  
  1578. 18.15c:    Where are some collections of useful code fragments and
  1579.     examples?
  1580.  
  1581. A:    See the full list for a few sources.
  1582.  
  1583. 18.15d:    I need code for performing multiple precision arithmetic.
  1584.  
  1585. A:    See the full list for a few ideas.
  1586.  
  1587. 18.16:    Where and how can I get copies of all these freely distributable
  1588.     programs?
  1589.  
  1590. A:    See the regular postings in the comp.sources.unix and
  1591.     comp.sources.misc newsgroups, or the full version of this list,
  1592.     for information.
  1593.  
  1594.  
  1595. Section 19. System Dependencies
  1596.  
  1597. 19.1:    How can I read a single character from the keyboard without
  1598.     waiting for the RETURN key?
  1599.  
  1600. A:    Alas, there is no standard or portable way to do this sort of
  1601.     thing in C.
  1602.  
  1603. 19.2:    How can I find out how many characters are available for
  1604.     reading, or do a non-blocking read?
  1605.  
  1606. A:    These, too, are entirely operating-system-specific.
  1607.  
  1608. 19.3:    How can I display a percentage-done indication that updates
  1609.     itself in place, or show one of those "twirling baton" progress
  1610.     indicators?
  1611.  
  1612. A:    The character '\r' is a carriage return, and '\b' is a
  1613.     backspace.
  1614.  
  1615. 19.4:    How can I clear the screen, or print text in color, or move the
  1616.     cursor?
  1617.  
  1618. A:    The only halfway-portable solution is the curses library.
  1619.  
  1620. 19.5:    How do I read the arrow keys?  What about function keys?
  1621.  
  1622. A:    Such things depend on the keyboard, operating system, and
  1623.     library you're using.
  1624.  
  1625. 19.6:    How do I read the mouse?
  1626.  
  1627. A:    What system are you using?
  1628.  
  1629. 19.7:    How can I do serial ("comm") port I/O?
  1630.  
  1631. A:    It's system-dependent.
  1632.  
  1633. 19.8:    How can I direct output to the printer?
  1634.  
  1635. A:    See the full list for ideas.
  1636.  
  1637. 19.9:    How do I send escape sequences to control a terminal or other
  1638.     device?
  1639.  
  1640. A:    By sending them.  ESC is '\033' in ASCII.
  1641.  
  1642. 19.10:    How can I do graphics?
  1643.  
  1644. A:    There is no portable way.
  1645.  
  1646. 19.11:    How can I check whether a file exists?
  1647.  
  1648. A:    You can try the access() or stat() functions.  Otherwise, the
  1649.     only guaranteed and portable way is to try opening the file.
  1650.  
  1651. 19.12:    How can I find out the size of a file, prior to reading it in?
  1652.  
  1653. A:    You might be able to get an estimate using stat() or fseek/ftell
  1654.     (but see the full list for caveats).
  1655.  
  1656. 19.12b:    How can I find the modification date of a file?
  1657.  
  1658. A:    Try stat().
  1659.  
  1660. 19.13:    How can a file be shortened in-place without completely clearing
  1661.     or rewriting it?
  1662.  
  1663. A:    There are various ways to do this, but there is no portable
  1664.     solution.
  1665.  
  1666. 19.14:    How can I insert or delete a line in the middle of a file?
  1667.  
  1668. A:    Short of rewriting the file, you probably can't.
  1669.  
  1670. 19.15:    How can I recover the file name given an open file descriptor?
  1671.  
  1672. A:    This problem is, in general, insoluble.  It is best to remember
  1673.     the names of files yourself as you open them
  1674.  
  1675. 19.16:    How can I delete a file?
  1676.  
  1677. A:    The Standard C Library function is remove().
  1678.  
  1679. 19.16b:    How do I copy files?
  1680.  
  1681. A:    Open the source and destination files and copy a character or
  1682.     block at a time, or see question 19.27.
  1683.  
  1684. 19.17:    What's wrong with the call fopen("c:\newdir\file.dat", "r")?
  1685.  
  1686. A:    You probably need to double those backslashes.
  1687.  
  1688. 19.18:    How can I increase the allowable number of simultaneously open
  1689.     files?
  1690.  
  1691. A:    Check your system documentation.
  1692.  
  1693. 19.20:    How can I read a directory in a C program?
  1694.  
  1695. A:    See if you can use the opendir() and readdir() functions.
  1696.  
  1697. 19.22:    How can I find out how much memory is available?
  1698.  
  1699. A:    Your operating system may provide a routine which returns this
  1700.     information.
  1701.  
  1702. 19.23:    How can I allocate arrays or structures bigger than 64K?
  1703.  
  1704. A:    Some operating systems won't let you.
  1705.  
  1706. 19.24:    What does the error message "DGROUP exceeds 64K" mean?
  1707.  
  1708. A:    It means that you have too much static data.
  1709.  
  1710. 19.25:    How can I access memory located at a certain address?
  1711.  
  1712. A:    Set a pointer to the absolute address.
  1713.  
  1714. 19.27:    How can I invoke another program from within a C program?
  1715.  
  1716. A:    Use system().
  1717.  
  1718. 19.30:    How can I invoke another program and trap its output?
  1719.  
  1720. A:    Unix and some other systems provide a popen() function.
  1721.  
  1722. 19.31:    How can my program discover the complete pathname to the
  1723.     executable from which it was invoked?
  1724.  
  1725. A:    argv[0] may contain all or part of the pathname.  You may be
  1726.     able to duplicate the command language interpreter's search path
  1727.     logic to locate the executable.
  1728.  
  1729. 19.32:    How can I automatically locate a program's configuration files
  1730.     in the same directory as the executable?
  1731.  
  1732. A:    It's hard; see also question 19.31 above.
  1733.  
  1734. 19.33:    How can a process change an environment variable in its caller?
  1735.  
  1736. A:    If it's possible to do so at all, it's system dependent.
  1737.  
  1738. 19.36:    How can I read in an object file and jump to locations in it?
  1739.  
  1740. A:    You want a dynamic linker or loader.
  1741.  
  1742. 19.37:    How can I implement a delay, or time a user's response, with sub-
  1743.     second resolution?
  1744.  
  1745. A:    Unfortunately, there is no portable way.
  1746.  
  1747. 19.38:    How can I trap or ignore keyboard interrupts like control-C?
  1748.  
  1749. A:    Use signal().
  1750.  
  1751. 19.39:    How can I handle floating-point exceptions gracefully?
  1752.  
  1753. A:    Take a look at matherr() and signal(SIGFPE).
  1754.  
  1755. 19.40:    How do I...  Use sockets?  Do networking?  Write client/server
  1756.     applications?
  1757.  
  1758. A:    These questions have more to do with the networking facilities
  1759.     you have available than they do with C.
  1760.  
  1761. 19.40b:    How do I...  Use BIOS calls?  Write ISR's?  Create TSR's?
  1762.  
  1763. A:    These are very particular to a particular system.
  1764.  
  1765. 19.40c:    I'm trying to compile a program in which "union REGS" and
  1766.     int86() are undefined.
  1767.  
  1768. A:    Those have to do with MS-DOS interrupt programming.
  1769.  
  1770. 19.41:    But I can't use all these nonstandard, system-dependent
  1771.     functions, because my program has to be ANSI compatible!
  1772.  
  1773. A:    That's an impossible requirement.  Any real program requires at
  1774.     least a few services which ANSI doesn't define.
  1775.  
  1776.  
  1777. Section 20. Miscellaneous
  1778.  
  1779. 20.1:    How can I return multiple values from a function?
  1780.  
  1781. A:    Either pass pointers to several locations which the function can
  1782.     fill in, or have the function return a structure containing the
  1783.     desired values.
  1784.  
  1785. 20.3:    How do I access command-line arguments?
  1786.  
  1787. A:    Via main()'s argv parameter.
  1788.  
  1789. 20.5:    How can I write data files which can be read on other machines
  1790.     with different data formats?
  1791.  
  1792. A:    The most portable solution is to use text files.
  1793.  
  1794. 20.6:    How can I call a function, given its name as a string?
  1795.  
  1796. A:    The most straightforward thing to do is to maintain a
  1797.     correspondence table of names and function pointers.
  1798.  
  1799. 20.8:    How can I implement sets or arrays of bits?
  1800.  
  1801. A:    Use arrays of char or int, with a few macros to access the
  1802.     desired bit at the proper index.
  1803.  
  1804. 20.9:    How can I determine whether a machine's byte order is big-endian
  1805.     or little-endian?
  1806.  
  1807. A:    The usual tricks involve pointers or unions.
  1808.  
  1809. 20.10:    How can I convert integers to binary or hexadecimal?
  1810.  
  1811. A:    Internally, integers are already in binary.  During I/O, you may
  1812.     be able to select a base.
  1813.  
  1814. 20.11:    Can I use base-2 constants (something like 0b101010)?
  1815.     Is there a printf() format for binary?
  1816.  
  1817. A:    No, on both counts.
  1818.  
  1819. 20.12:    What is the most efficient way to count the number of bits which
  1820.     are set in an integer?
  1821.  
  1822. A:    Many "bit-fiddling" problems like this one can be sped up and
  1823.     streamlined using lookup tables.
  1824.  
  1825. 20.13:    What's the best way of making my program efficient?
  1826.  
  1827. A:    By picking good algorithms and implementing them carefully.
  1828.  
  1829. 20.14:    Are pointers really faster than arrays?  How much do function
  1830.     calls slow things down?
  1831.  
  1832. A:    Precise answers to these and many similar questions depend on
  1833.     the processor and compiler in use.
  1834.  
  1835. 20.15b:    People claim that optimizing compilers are good, but mine can't
  1836.     even replace i/=2 with a shift.
  1837.  
  1838. A:    Was i signed or unsigned?
  1839.  
  1840. 20.15c:    How can I swap two values without using a temporary?
  1841.  
  1842. A:    The "clever" trick is a ^= b; b ^= a; a ^= b; see also question
  1843.     3.3b.
  1844.  
  1845. 20.17:    Is there a way to switch on strings?
  1846.  
  1847. A:    Not directly.
  1848.  
  1849. 20.18:    Is there a way to have non-constant case labels (i.e. ranges or
  1850.     arbitrary expressions)?
  1851.  
  1852. A:    No.
  1853.  
  1854. 20.19:    Are the outer parentheses in return statements really optional?
  1855.  
  1856. A:    Yes.
  1857.  
  1858. 20.20:    Why don't C comments nest?  Are they legal inside quoted
  1859.     strings?
  1860.  
  1861. A:    C comments don't nest because PL/I's comments don't either.  The
  1862.     character sequences /* and */ are not special within double-
  1863.     quoted strings.
  1864.  
  1865. 20.20b:    What does a+++++b mean ?
  1866.  
  1867. A:    Nothing.  It's interpreted as "a ++ ++ + b", and cannot be
  1868.     parsed.
  1869.  
  1870. 20.24:    Why doesn't C have nested functions?
  1871.  
  1872. A:    They were deliberately left out of C as a simplification.
  1873.  
  1874. 20.24b:    What is assert()?
  1875.  
  1876. A:    It is a macro which documents an assumption being made by the
  1877.     programmer; it terminates the program if the assumption is
  1878.     violated.
  1879.  
  1880. 20.25:    How can I call FORTRAN (C++, BASIC, Pascal, Ada, LISP) functions
  1881.     from C?
  1882.  
  1883. A:    The answer is entirely dependent on the machine and the specific
  1884.     calling sequences of the various compilers in use.
  1885.  
  1886. 20.26:    Does anyone know of a program for converting Pascal or FORTRAN
  1887.     to C?
  1888.  
  1889. A:    Several freely distributable programs are available, namely
  1890.     ptoc, p2c, and f2c.  See the full list for details.
  1891.  
  1892. 20.27:    Can I use a C++ compiler to compile C code?
  1893.  
  1894. A:    Not necessarily; C++ is not a strict superset of C.
  1895.  
  1896. 20.28:    I need to compare two strings for close, but not necessarily
  1897.     exact, equality.
  1898.  
  1899. A:    See the full list for ideas.
  1900.  
  1901. 20.29:    What is hashing?
  1902.  
  1903. A:    A mapping of strings (or other data structures) to integers, for
  1904.     easier searching.
  1905.  
  1906. 20.31:    How can I find the day of the week given the date?
  1907.  
  1908. A:    Use mktime(), Zeller's congruence, or some code in the full
  1909.     list.
  1910.  
  1911. 20.32:    Will 2000 be a leap year?
  1912.  
  1913. A:    Yes.
  1914.  
  1915. 20.34:    How do you write a program which produces its own source code as
  1916.     output?
  1917.  
  1918. A:    Here's one:
  1919.  
  1920.         char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";
  1921.         main(){printf(s,34,s,34);}
  1922.  
  1923. 20.35:    What is "Duff's Device"?
  1924.  
  1925. A:    It's a devastatingly deviously unrolled byte-copying loop.  See
  1926.     the full list for details.
  1927.  
  1928. 20.36:    When will the next Obfuscated C Code Contest be held?
  1929.     How can I get a copy of previous winning entries?
  1930.  
  1931. A:    See the full list, or http://www.ioccc.org/index.html .
  1932.  
  1933. 20.37:    What was the entry keyword mentioned in K&R1?
  1934.  
  1935. A:    It was reserved to allow functions with multiple, differently-
  1936.     named entry points, but it has been withdrawn.
  1937.  
  1938. 20.38:    Where does the name "C" come from, anyway?
  1939.  
  1940. A:    C was derived from B, which was inspired by BCPL, which was a
  1941.     simplification of CPL.
  1942.  
  1943. 20.39:    How do you pronounce "char"?
  1944.  
  1945. A:    Like the English words "char," "care," or "car" (your choice).
  1946.  
  1947. 20.39b:    What do "lvalue" and "rvalue" mean?
  1948.  
  1949. A:    An "lvalue" denotes an object that has a location; an "rvalue"
  1950.     is any expression that has a value.
  1951.  
  1952. 20.40:    Where can I get extra copies of this list?
  1953.  
  1954. A:    An up-to-date copy may be obtained from ftp.eskimo.com in
  1955.     directory u/s/scs/C-faq/.  You can also just pull it off the
  1956.     net; the unabridged version is normally posted on the first of
  1957.     each month, with an Expires: line which should keep it around
  1958.     all month.  It is also posted to the newsgroups comp.answers and
  1959.     news.answers .  Several sites archive news.answers postings and
  1960.     other FAQ lists, including this one; two sites are rtfm.mit.edu
  1961.     (directory pub/usenet), and ftp.uu.net (directory usenet).
  1962.  
  1963.     A hypertext version of this FAQ list is available at
  1964.     http://www.eskimo.com/~scs/C-faq/top.html .
  1965.     An extended version has been published by Addison-Wesley
  1966.     as _C Programming FAQs: Frequently Asked Questions_
  1967.     (ISBN 0-201-84519-9).
  1968.  
  1969.                         Steve Summit
  1970.                         scs@eskimo.com
  1971.  
  1972.  
  1973. This article is Copyright 1990-1999 by Steve Summit.
  1974. Content from the book _C Programming FAQs: Frequently Asked Questions_
  1975. is made available here by permission of the author and the publisher as
  1976. a service to the community.  It is intended to complement the use of the
  1977. published text and is protected by international copyright laws.  The
  1978. content is made available here and may be accessed freely for personal
  1979. use but may not be republished without permission.
  1980.