home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / C-faq / diff < prev    next >
Encoding:
Internet Message Format  |  1993-05-03  |  29.0 KB

  1. Path: senator-bedfellow.mit.edu!adam.mit.edu!scs
  2. From: scs@adam.mit.edu (Steve Summit)
  3. Newsgroups: comp.lang.c,comp.answers,news.answers
  4. Subject: comp.lang.c Changes to Answers to Frequently Asked Questions (FAQ)
  5. Followup-To: poster
  6. Date: 3 May 1993 13:53:46 GMT
  7. Organization: none, at the moment
  8. Lines: 693
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <1s385aINNroo@senator-bedfellow.MIT.EDU>
  11. Reply-To: scs@adam.mit.edu
  12. NNTP-Posting-Host: adam.mit.edu
  13. X-Archive-name: C-faq/diff
  14. Xref: senator-bedfellow.mit.edu comp.lang.c:69641 comp.answers:610 news.answers:8131
  15.  
  16. Archive-name: C-faq/diff
  17. Comp-lang-c-archive-name: C-FAQ-list.diff
  18.  
  19. This article contains changes between the previous revision of
  20. the comp.lang.c frequently-asked questions list (posted on April 1,
  21. last modified on February 1) and the new one.  (Do _not_ worry if
  22. you have not seen the new one yet; it's coming up next.)  As
  23. usual, these diffs have been edited for readability, and are not
  24. suitable for use with the patch program.
  25.  
  26. This release, as you'll see, represents another fairly large set
  27. of additions.  The list is up to about 122k, and my formerly
  28. steadfast resolve to keep it in one piece is flagging.  (Some
  29. sites aren't receiving it, and its size is a likely factor.)
  30. I am on the brink of splitting it up; if you'd like to encourage
  31. (or discourage!) this move, now would be a good time to do so.
  32.  
  33. As I mentioned last month, I am trying to track down propagation
  34. problems -- if your site receives this message and/or the
  35. abridged FAQ list but not the full, 122k FAQ list, please let me
  36. know (and, if possible, please include a header, or at least the
  37. Path: line, from one of the messages you do receive).
  38.  
  39. As always, I am actively soliciting feedback on the FAQ list.
  40. If you feel that it isn't doing its job well (because of its
  41. size, or the level or tone of its answers), or if you think that
  42. it could be improved in some way, please let me know.  I can't
  43. promise to make major changes, but I do promise to listen.  (On
  44. the other hand, sometimes I tinker with the list too much -- if
  45. you feel it's fine as it is, I always love to hear that, too :-) .)
  46.  
  47. One change I'm contemplating making (after noticing how handy it
  48. is in several FAQ lists which I've had occasion to consult
  49. recently) is a full table of contents, listing questions only.
  50. This was suggested long ago, but I always felt that it would
  51. increase the list's size unacceptably (which it would).  I'm now
  52. thinking of posting the table of contents as a separate article --
  53. although this has the obvious drawback that, if downloading FAQ
  54. lists is a chore (which it certainly can be), once you've found a
  55. question in the TOC, you have another downloading chore before
  56. you can find the answer.  If you think that posting a separate
  57. TOC is a particularly good (or bad) idea, let me know.
  58.  
  59. ==========
  60. < [Last modified February 1, 1993 by scs.]
  61. ---
  62. > [Last modified May 2, 1993 by scs.]
  63. ==========
  64. >    The Eclipse MV series from Data General has three
  65. >    architecturally supported pointer formats (word, byte, and bit
  66. >    pointers), two of which are used by C compilers: byte pointers
  67. >    for char * and void *, and word pointers for everything else.
  68. >
  69. >    The CDC Cyber 180 Series has 48-bit pointers consisting of a
  70. >    ring, segment, and offset.  Most users (in ring 11) have null
  71. >    pointers of 0xB00000000000.
  72. ==========
  73. > 1.15:    What does a run-time "null pointer assignment" error mean?  How
  74. >    do I track it down?
  75. > A:    This message, which occurs only under MS-DOS (see, therefore,
  76. >    section 16) means that you've written, via a null pointer, to
  77. >    location zero.
  78. >    A debugger will usually let you set a data breakpoint on
  79. >    location 0.  Alternately, you could write a bit of code to copy
  80. >    20 or so bytes from location 0 into another buffer, and
  81. >    periodically check that it hasn't changed.
  82. ==========
  83. <    It is important to remember that a reference like x[3] generates
  84. ---
  85. >    It is important to realize that a reference like x[3] generates
  86.     different code depending on whether x is an array or a pointer.
  87. ==========
  88.     "Equivalence" refers to the following key definition:
  89.  
  90. >        An lvalue [see question 2.5] of type array-of-T
  91.         which appears in an expression decays (with
  92. ==========
  93. <    As a consequence of this definition, there is not really any
  94. ---
  95. >    As a consequence of this definition, there is no apparent
  96.     difference in the behavior of the "array subscripting" operator
  97.     [] as it applies to arrays and pointers.  In an expression of
  98. ==========
  99.     the form a[i], the array reference "a" decays into a pointer,
  100. <    following the rule above, and is then subscripted exactly as
  101. <    would be a pointer variable in the expression p[i].  In either
  102. ---
  103. >    following the rule above, and is then subscripted just as would
  104. >    be a pointer variable in the expression p[i] (although the
  105. >    eventual memory accesses will be different, as explained in
  106. >    question 2.2).  In either case, the expression x[i] (where x is
  107.     an array or a pointer) is, by definition, exactly equivalent to
  108.     *((x)+(i)).
  109. ==========
  110. > 2.5:    How can an array be an lvalue, if you can't assign to it?
  111. > A:    The ANSI C Standard defines a "modifiable lvalue," which an
  112. >    array is not.
  113. >    References: ANSI Sec. 3.2.2.1 p. 37.
  114. ==========
  115. > 2.8:    Practically speaking, what is the difference between arrays and
  116. >    pointers?
  117. > A:    Arrays automatically allocate space, but can't be relocated or
  118. >    resized.  Pointers must be explicitly assigned to point to
  119. >    allocated space (perhaps using malloc), but can be reassigned
  120. >    (i.e. pointed at different objects) at will, and have many other
  121. >    uses besides serving as the base of blocks of memory.
  122. >    Due to the "equivalence of arrays and pointers" (see question
  123. >    2.3), arrays and pointers often seem interchangeable, and in
  124. >    particular a pointer to a block of memory assigned by malloc is
  125. >    frequently treated (and can be referenced using [] exactly) as
  126. >    if it were a true array (see also question 2.13).
  127. ==========
  128. > 2.11:    How do I write functions which accept 2-dimensional arrays when
  129. >    the "width" is not known at compile time?
  130. > A:    It's not easy.  One way is to pass in pointer to the [0][0]
  131. >    element, along with the two dimensions, and simulate array
  132. >    subscripting "by hand:"
  133. >        f2(aryp, m, n)
  134. >        int *aryp;
  135. >        int m, n;
  136. >        { ... ary[i][j] is really aryp[i * n + j] ... }
  137. >    This function could be called with the array from question 2.10
  138. >    as
  139. >        f2(&array[0][0], NROWS, NCOLUMNS);
  140. >    See also question 2.14.
  141. ==========
  142.   Q:    How do I declare a pointer to an array?
  143.  
  144. < A:    Usually, you don't want to.  Consider using a pointer to one of
  145. <    the array's elements instead.  Arrays of type T decay into
  146. <    pointers to type T (see question 2.3), which is convenient;
  147. ---
  148. > A:    Usually, you don't want to.  When people speak casually of a
  149. >    pointer to an array, they usually mean a pointer to its first
  150. >    element.
  151. >    Instead of a pointer to an array, consider using a pointer to
  152. >    one of the array's elements instead.  Arrays of type T decay
  153. >    into pointers to type T (see question 2.3), which is convenient;
  154. ==========
  155. <    all.  (See question 2.8 above.)  When people speak casually of a
  156. <    pointer to an array, they usually mean a pointer to its first
  157. <    element.
  158. ---
  159. >    all.  (See question 2.10 above.)
  160. ==========
  161.   2.13:    How can I dynamically allocate a multidimensional array?
  162.  
  163.   A:    It is usually best to allocate an array of pointers, and then
  164. <    initialize each pointer to a dynamically-allocated "row."  The
  165. <    resulting "ragged" array can save space, although it is not
  166. <    necessarily contiguous in memory as a real array would be.  Here
  167. ---
  168. >    initialize each pointer to a dynamically-allocated "row."  Here
  169.     is a two-dimensional example:
  170. ==========
  171.     With all of these techniques, you may of course need to remember
  172. <    to free the arrays (which may take several steps) when they are
  173. <    no longer needed.  You must also be extremely cautious when
  174. <    passing dynamically-allocated arrays down to other functions, if
  175. <    those functions are also to accept conventional, statically-
  176. <    allocated arrays (see question 2.8).
  177. ---
  178. >    to free the arrays (which may take several steps; see question
  179. >    3.8) when they are no longer needed, and you cannot necessarily
  180. >    intermix the dynamically-allocated arrays with conventional,
  181. >    statically-allocated ones (see question 2.14 below, and also
  182. >    question 2.10).
  183. ==========
  184. > 2.14:    How can I use statically- and dynamically-allocated
  185. >    multidimensional arrays interchangeably when passing them to
  186. >    functions?
  187. > A:    There is no single perfect method.  Given the array and f() as
  188. >    declared in question 2.10, f2() as declared in question 2.11,
  189. >    array1, array2, array3, and array4 as declared in 2.13, and a
  190. >    function f3() declared as:
  191. >        f3(pp, m, n)
  192. >        int **pp;
  193. >        int m, n;
  194. >    ; the following calls would be legal, and work as expected:
  195. >        f(array, NROWS, NCOLUMNS);
  196. >        f(array4, nrows, NCOLUMNS);
  197. >        f2(&array[0][0], NROWS, NCOLUMNS);
  198. >        f2(*array2, nrows, ncolumns);
  199. >        f2(array3, nrows, ncolumns);
  200. >        f2(*array4, nrows, NCOLUMNS);
  201. >        f3(array1, nrows, ncolumns);
  202. >        f3(array2, nrows, ncolumns);
  203. >    The following two calls would probably work, but involve
  204. >    questionable casts, and work only if the dynamic ncolumns
  205. >    matches the static NCOLUMNS:
  206. >        f((int (*)[NCOLUMNS])(*array2), nrows, ncolumns);
  207. >        f((int (*)[NCOLUMNS])array3, nrows, ncolumns);
  208. >    If you can understand why all of the above calls work and are
  209. >    written as they are, and if you understand why the combinations
  210. >    that are not listed would not work, then you have a _very_ good
  211. >    understanding of arrays and pointers (and several other areas)
  212. >    in C.
  213. ==========
  214. <    This technique, though attractive, is not strictly conforming to
  215. <    the C standards (in spite of its appearance in Numerical Recipes
  216. <    in C).  
  217. ---
  218. >    Although this technique is attractive (and is used in the book
  219. >    Numerical Recipes in C), it does not conform to the C standards.
  220. ==========
  221. > 3.8:    I'm allocating structures which contain pointers to other
  222. >    dynamically-allocated objects.  When I free a structure, do I
  223. >    have to free each subsidiary pointer first?
  224. > A:    Yes.  In general, you must arrange that each pointer returned
  225. >    from malloc be individually passed to free, exactly once (if it
  226. >    is freed at all).
  227. ==========
  228. > 3.9:    I have a program which mallocs but then frees a lot of memory,
  229. >    but memory usage (as reported by ps) doesn't seem to go back
  230. >    down.
  231. > A:    Most implementations of malloc/free do not return freed memory
  232. >    to the operating system (if there is one), but merely make it
  233. >    available for future malloc calls.
  234. ==========
  235.   5.3:    Does anyone have a tool for converting old-style C programs to
  236.     ANSI C, or vice versa, or for automatically generating
  237.     prototypes?
  238.  
  239. > A:    First, are you sure you really need to convert lots of old code
  240. >    to ANSI C?  The old-style function syntax is still acceptable.
  241.  
  242.     Two programs, protoize and unprotoize, convert back and forth
  243. ==========
  244. > 5.6:    Why can't I pass a char ** to a function which expects a
  245. >    const char **?
  246. > A:    You can use a pointer-to-T (for any type T) where a pointer-to-
  247. >    const-T is expected, but the rule (an explicit exception) which
  248. >    permits slight mismatches in qualified pointer types is not
  249. >    applied recursively, but only at the top level.
  250. >    You must use explicit casts (e.g. (const char **) in this case)
  251. >    when assigning (or passing) pointers which have qualifier
  252. >    mismatches at other than the first level of indirection.
  253. >    References: ANSI Sec. 3.1.2.6 p. 26, Sec. 3.3.16.1 p. 54,
  254. >    Sec. 3.5.3 p. 65.
  255. ==========
  256.     "int func(x) float x;".  Old C (and ANSI C, in the absence of
  257.     prototypes, and in variable-length argument lists) "widens"
  258. <    certain arguments when they are passed to functions.  floats
  259. <    are promoted to double, and characters and short integers are
  260. <    promoted to integers.  (The values are automatically coerced
  261. ---
  262. >    certain arguments when they are passed to functions.  Type float
  263. >    is promoted to double, and characters and short integers are
  264. >    promoted to integers.  (The values are automatically converted
  265.     back to the corresponding narrower types within the body of the
  266. ==========
  267. > 5.8:    Why does the declaration
  268. >        extern f(struct x {int s;} *p);
  269. >    give me an obscure warning message about "struct x introduced in
  270. >    prototype scope"?
  271. > A:    In a quirk of C's normal block scoping rules, a struct declared
  272. >    only within a prototype cannot be compatible with other structs
  273. >    declared in the same source file, nor can the struct tag be used
  274. >    later as you'd expect (it goes out of scope at the end of the
  275. >    prototype).
  276. >    To resolve the problem, precede the prototype with the vacuous-
  277. >    looking declaration
  278. >
  279. >        struct x;
  280. >    , which will reserve a place at file scope for struct x's
  281. >    definition, which will be completed by the struct declaration
  282. >    within the prototype.
  283. >    References: ANSI Sec. 3.1.2.1 p. 21, Sec. 3.1.2.6 p. 26,
  284. >    Sec. 3.5.2.3 p. 63.
  285. ==========
  286. > 5.11:    Is exit(status) truly equivalent to returning status from main?
  287. > A:    Yes, except under a few older, nonconforming systems.
  288. >    References: ANSI Sec. 2.1.2.2.3 p. 8.
  289. ==========
  290. > 5.16:    Is char a[3] = "abc"; legal?  What does it mean?
  291. > A:    Yes, it is legal; it declares an array of size three,
  292. >    initialized with the three characters 'a', 'b', and 'c', without
  293. >    the usual terminating '\0' character.
  294. >    References: ANSI Sec. 3.5.7 pp. 72-3.
  295. ==========
  296.   6.5:    Does the sizeof operator work in preprocessor #if directives?
  297.  
  298.   A:    No.  Preprocessing happens during an earlier pass of
  299.     compilation, before type names have been parsed.  Consider using
  300. <    the predefined constants in ANSI's <limits.h>, or a "configure"
  301. <    script, instead.
  302. ---
  303. >    the predefined constants in ANSI's <limits.h>, if applicable, or
  304. >    a "configure" script, instead.  (Better yet, try to write code
  305. >    which is inherently insensitive to type sizes.)
  306. ==========
  307. > 6.8:    I have some code which contains far too many #ifdef's for my
  308. >    taste.  How can I preprocess the code to leave only one
  309. >    conditional compilation set, without running it through cpp and
  310. >    expanding all of the #include's and #define's as well?
  311. > A:    There is a program floating around called unifdef which does
  312. >    exactly this.  (See question 17.8.)
  313. ==========
  314. > 6.9:    How can I list all of the pre#defined identifiers?
  315. > A:    There's no standard way, although it is a frequent need.  The
  316. >    most expedient way is probably to extract printable strings from
  317. >    the compiler or preprocessor executable with something like the
  318. >    Unix strings(1) utility.
  319. ==========
  320.     The obvious disadvantage is that the caller must always remember
  321. <    to use the extra parentheses.  (It is often better to use a
  322. ---
  323. >    to use the extra parentheses.  Another solution is to use
  324. >    different macros (DEBUG1, DEBUG2, etc.) depending on the number
  325. >    of arguments.  (It is often better to use a bona-fide function,
  326. ==========
  327. > 7.4:    I can't get the va_arg macro to pull in an argument of type
  328. >    pointer-to-function.
  329. > A:    The type-rewriting games which the va_arg macro typically plays
  330. >    are stymied by overly-complicated types such as pointer-to-
  331. >    function.  If you use a typedef for the function pointer type,
  332. >    however, all will be well.
  333. >    References: ANSI Sec. 4.8.1.2 p. 124.
  334. ==========
  335. <    The primary advantages of enums are that the numeric values are
  336. <    automatically assigned, and that a debugger may be able to
  337. <    display the symbolic values when enum variables are examined.
  338. ---
  339. >    Some advantages of enums are that the numeric values are
  340. >    automatically assigned, that a debugger may be able to display
  341. >    the symbolic values when enum variables are examined, and that
  342. >    they obey block scope.
  343. ==========
  344. > 10.2:    What should the 64-bit type on new, 64-bit machines be?
  345. > A:    Some vendors of C products for 64-bit machines support 64-bit
  346. >    long ints.  Others fear that too much existing code depends on
  347. >    sizeof(int) == sizeof(long) == 32 bits, and introduce a new 64-
  348. >    bit long long int type instead.
  349. >    Programmers interested in writing portable code should therefore
  350. >    insulate their 64-bit type needs behind appropriate typedefs.
  351. >    Vendors who feel compelled to introduce a new long long int type
  352. >    should advertise it as being "at least 64 bits" (which is truly
  353. >    new; a type traditional C doesn't have), and not "exactly 64
  354. >    bits."
  355. ==========
  356.     complete at the point where the "next" field is declared.  To
  357.     fix it, first give the structure a tag ("struct node").  Then,
  358.     declare the "next" field as "struct node *next;", and/or move
  359.     the typedef declaration wholly before or wholly after the struct
  360. <    declaration.  One fixed version would be
  361. ---
  362. >    declaration.  One corrected version would be
  363. ==========
  364. > 11.2:    Why doesn't the code scanf("%d", i); work?
  365. > A:    You must always pass addresses (in this case, &i) to scanf.
  366. ==========
  367. > 11.3:    Why doesn't this code:
  368. >        double d;
  369. >        scanf("%f", &d);
  370. >    work?
  371. > A:    With scanf, use %lf for values of type double, and %f for float.
  372. >    (Note the discrepancy with printf, which uses %f for both double
  373. >    and float, due to C's default argument promotion rules.)
  374. ==========
  375. > 11.4:    Why won't the code
  376. >        while(!feof(fp))
  377. >            fgets(buf, MAXLINE, fp);
  378. >    work?
  379. > A:    C's I/O is not like Pascal's.  EOF is only indicated _after_ an
  380. >    input routine has tried to read, and has reached end-of-file.
  381. >    Usually, you should just check the return value of the input
  382. >    routine (fgets in this case); feof() is rarely needed.
  383. ==========
  384. > 11.5:    Why does everyone say not to use gets()?
  385. > A:    It cannot be told the size of the buffer it's to read into, so
  386. >    it cannot be prevented from overflowing that buffer.
  387. ==========
  388. <    It 
  389. ---
  390. >    A related problem is that unexpected non-numeric input can cause
  391. >    scanf to "jam."  Because of these problems, it is usually better
  392.     to use fgets() to read a whole line, and then use sscanf or
  393.     other string functions to pick apart the line buffer.
  394. ==========
  395. > 11.9:    I'm trying to update a file in place, by using fopen mode "r+",
  396. >    then reading a certain string, and finally writing back a
  397. >    modified string, but it's not working.
  398. > A:    Be sure to call fseek before you write, both to seek back to the
  399. >    beginning of the string you're trying to overwrite, and because
  400. >    an fseek or fflush is always required between reading and
  401. >    writing in the read/write "+" modes.
  402. >    References: ANSI Sec. 4.9.5.3 p. 131.
  403. ==========
  404. > 11.10: How can I read one character at a time, without waiting for the
  405. >    RETURN key?
  406. > A:    See question 16.1.
  407. ==========
  408. > 11.12: How can I redirect stdin or stdout to a file from within a
  409. >    program?
  410. > A:    Use freopen.
  411. ==========
  412. > 12.1:    Why does strncpy not always place a '\0' termination in the
  413. >    destination string?
  414. > A:    strncpy was first designed to handle a now-obsolete data
  415. >    structure, the fixed-length, not-necessarily-\0-terminated
  416. >    "string."  strncpy is admittedly a bit cumbersome to use in
  417. >    other contexts, since you must often append a '\0' to the
  418. >    destination string by hand.
  419. ==========
  420.     The comparison routine's arguments are expressed as "generic
  421. <    pointers," void * or char *.  They must be converted back to
  422. ---
  423. >    pointers," const void * or char *.  They must be converted back
  424.     to what they "really are" (char **) and dereferenced, yielding
  425. ==========
  426.         int pstrcmp(p1, p2)    /* compare strings through pointers */
  427. <        char *p1, *p2;        /* void * for ANSI C */
  428. ---
  429. >        char *p1, *p2;          /* const void * for ANSI C */
  430. ==========
  431.   A:    The conversions must be in the comparison function, which must
  432. <    be declared as accepting "generic pointers" (void * or char *)
  433. <    as discussed above.
  434. ---
  435. >    be declared as accepting "generic pointers" (const void * or
  436. >    char *) as discussed above.
  437. ==========
  438. < 12.4:    How can I get the time of day in a C program?
  439. ---
  440. > 12.5:    How can I get the current date or time of day in a C program?
  441. ==========
  442.             time(&now);
  443.             printf("It's %.24s.\n", ctime(&now));
  444. <            exit(0);
  445. ---
  446. >            return 0;
  447. ==========
  448.   A:    You can call srand() to seed the pseudo-random number generator
  449. <    with a more random initial value.  Popular random initial seeds
  450.     are the time of day, or the elapsed time before the user presses
  451. <    a key.
  452. ---
  453. >    with a more random initial value.  Popular seed values are the
  454.     time of day, or the elapsed time before the user presses a key
  455. >    (although keypress times are hard to determine portably; see
  456. >    question 16.9).
  457. ==========
  458. < A:    Perhaps; perhaps not.  The test succeeds if the two strings are
  459. ---
  460. > A:    It is not particularly good style, although it is a popular
  461.     idiom.  The test succeeds if the two strings are equal, but its
  462.     form suggests that it tests for inequality.
  463. ==========
  464.   A:    Make sure you're linking against the correct math library.  For
  465. <    instance, under Unix, you usually need to use the -lm option at
  466. <    the end of the command line when compiling/linking.
  467. ---
  468. >    instance, under Unix, you usually need to use the -lm option,
  469. >    and at the _end_ of the command line, when compiling/linking.
  470. ==========
  471.     by not including code to handle %e, %f, and %g.  It happens that
  472.     Turbo C's heuristics for determining whether the program uses
  473.     floating point are insufficient, and the programmer must
  474. <    sometimes insert a dummy explicit floating-point call to force
  475. ---
  476. >    sometimes insert an extra, explicit call to a floating-point
  477. >    library routine to force loading of floating-point support.
  478. ==========
  479.     Posix systems).  Under MS-DOS, use getch().  Under VMS, try the
  480. <    Screen Management (SMG$) routines.  Under other operating
  481. ---
  482. >    Screen Management (SMG$) routines, or curses, or issue low-level
  483. >    $QIO's to ask for one character at a time.  Under other
  484. ==========
  485.   A:    Consult your system documentation, or ask on an appropriate
  486.     system-specific newsgroup (but check its FAQ list first).  Mouse
  487. <    handling is completely different under the X window system than
  488. <    it is under MS-DOS than it is on the Macintosh.
  489. ---
  490. >    handling is completely different under the X window system, MS-
  491. >    DOS, Macintosh, and probably every other system.
  492. ==========
  493. <    determine this number in advance.  Under Unix, the stat()
  494. <    function will give you an exact answer, and several other
  495. ---
  496. >    determine this number in advance.  Under Unix, the stat call
  497. >    will give you an exact answer, and several other systems supply
  498. ==========
  499.     answer.  You can fseek to the end and then use ftell, but this
  500.     usage is nonportable (it gives you an accurate answer only under
  501. <    Unix, and a guaranteed, but potentially approximate answer only
  502. <    for ANSI C "binary" files).
  503. ---
  504.     nonportable (it gives you an accurate answer only under Unix,
  505. >    and otherwise a quasi-accurate answer only for ANSI C "binary"
  506. >    files).
  507. ==========
  508. <    F_FREESP.  Under MS-DOS, you can sometimes use
  509. <    write(fd, "x", 0).  However, there is no truly portable
  510. ---
  511. >    F_FREESP.  Under MS-DOS, you can sometimes use write(fd, "", 0).
  512. >    However, there is no truly portable solution.
  513. ==========
  514. >    Other routines you might look for on your
  515. >    system include clock() and gettimeofday().  The select() and
  516. >    poll() calls (if available) can be pressed into service to
  517. >    implement simple delays.  On MS-DOS machines, it is possible to
  518. >    reprogram the system timer and timer interrupts.
  519. ==========
  520.     an awful lot about object file formats, relocation, etc.  Under
  521.     BSD Unix, you could use system() and ld -A to do the linking for
  522. <    you.  There is also a GNU package called "dld" which takes care
  523. <    of some or all of this.  See also question 7.5.
  524. ---
  525. >    you.  Many (most?) versions of SunOS and System V have the -ldl
  526. >    library which allows object files to be dynamically loaded.
  527. >    There is also a GNU package called "dld".  See also question 7.6.
  528. ==========
  529.   17.3:    How can I return several values from a function?
  530.  
  531.   A:    Either pass pointers to locations which the function can fill
  532.     in, or have the function return a structure containing the
  533. <    desired values.  See also questions 2.12, 3.4, and 9.2.
  534. ---
  535. >    desired values, or (in a pinch) consider global variables.  See
  536. >    also questions 2.16, 3.4, and 9.2.
  537. ==========
  538.     be possible at all.  Read your compiler documentation very
  539.     carefully; sometimes there is a "mixed-language programming
  540.     guide," although the techniques for passing arguments and
  541. <    ensuring correct run-time startup are often arcane.
  542. ---
  543. >    ensuring correct run-time startup are often arcane.  More
  544. >    information may be found in FORT.Z by Glenn Geers, available via
  545. >    anonymous ftp from suphys.physics.su.oz.au in the src directory.
  546. ==========
  547. <    obtain a current copy of the rules and other information, send
  548. ---
  549. >    obtain a current copy of the rules and guidelines, send e-mail
  550. ==========
  551. <        {apple,pyramid,sun,uunet}!hoptoad!obfuscate  or
  552. <        obfuscate@toad.com
  553. ---
  554. >        {apple,pyramid,sun,uunet}!hoptoad!judges  (not the addresses for
  555. >        judges@toad.com                   submitting entries)
  556. ==========
  557.     Contest winners are first announced at the Summer Usenix
  558. <    Conference in mid-June, and posted to the net in July.  Previous
  559. <    winners are available on uunet (see question 17.8) under the
  560. ---
  561. >    Conference in mid-June, and posted to the net sometime in July-
  562. >    August.  Winning entries from previous years (to 1984) are
  563. >    archived at uunet (see question 17.8) under the directory
  564. >    ~/pub/ioccc.
  565. ==========
  566. >    As a last resort, previous winners may be obtained by sending
  567. >    e-mail to the above address, using the Subject: "send YEAR
  568. >    winners", where YEAR is a single four-digit year, a year range,
  569. >    or "all".
  570. ==========
  571.   A:    These generally mean that your program tried to access memory it
  572.     shouldn't have, invariably as a result of improper pointer use,
  573. <    often involving malloc.
  574. ---
  575. >    often involving malloc (see question 17.17) or perhaps scanf
  576. >    (see question 11.2).
  577. ==========
  578. > 17.17: My program is crashing, apparently somewhere down inside malloc,
  579. >    but I can't see anything wrong with it.
  580. > A:    It is unfortunately very easy to corrupt malloc's internal data
  581. >    structures, and the resulting problems can be hard to track
  582. >    down.  The most common source of problems is writing more to a
  583. >    malloc'ed region than it was allocated to hold; a particularly
  584. >    common bug is to malloc(strlen(s)) instead of strlen(s) + 1.
  585. >    Other problems involve freeing pointers not obtained from
  586. >    malloc, or trying to realloc a null pointer (see question 3.10).
  587. >    A number of debugging packages exist to help track down malloc
  588. >    problems; one popular one is Conor P. Cahill's "dbmalloc".
  589. ==========
  590. < A:    Plum Hall (1 Spruce Ave., Cardiff, NJ 08232, USA), among others,
  591. <    sells one.
  592. ---
  593. > A:    Plum Hall (1 Spruce Ave., Cardiff, NJ 08232, USA) sells one.
  594. >    The FSF's GNU C (gcc) distribution includes a c-torture-
  595. >    test.tar.Z which checks a number of common problems with
  596. >    compilers.  Kahan's paranoia test, found in netlib on
  597. >    research.att.com, strenuously tests a C implementation's
  598. >    floating point capabilities.
  599. ==========
  600. <    open.  There is one on uunet (see question 17.8) in
  601. ---
  602. >    open.  There is one (due to Jeff Lee) on uunet (see question
  603. >    17.8) in usenet/net.sources/ansi.c.grammar.Z (including a
  604. >    companion lexer).  Another one, by Jim Roskind, is in
  605. >    pub/*grammar* at ics.uci.edu .  The FSF's GNU C compiler
  606.     contains a grammar, as does the appendix to K&R II.
  607. ==========
  608.     which should keep it around all month.  It can also be found in
  609. <    the newsgroup news.answers .  Several sites archive news.answers
  610. <    postings and other FAQ lists, including this one; the archie
  611. <    server (see question 17.8) should help you find them.  See the
  612. <    meta-FAQ list in news.answers for more information.
  613. ---
  614. >    the newsgroups comp.answers and news.answers .  Several sites
  615. >    archive news.answers postings and other FAQ lists, including
  616. >    this one: two sites are pit-manager.mit.edu (directory
  617. >    pub/usenet), and ftp.uu.net (directory usenet).  The archie
  618. >    server should help you find others.  See the meta-FAQ list in
  619. >    news.answers for more information; see also question 17.8.
  620. ==========
  621. <    This list is an evolving document, not just a collection of this
  622. ---
  623. >    This list is an evolving document of questions which have been
  624. >    Frequent since before the Great Renaming, not just a collection
  625.     of this month's interesting questions.
  626. ==========
  627. > Thanks to Jamshid Afshar, Sudheer Apte, Randall Atkinson, Dan Bernstein,
  628. > Vincent Broman, Stan Brown, Joe Buehler, Gordon Burditt, Burkhard Burow,
  629. > D'Arcy J.M. Cain, Raymond Chen, Christopher Calabrese, Paul Carter,
  630. > James Davies, Jutta Degener, Norm Diamond, Ray Dunn, Stephen M. Dunn,
  631. > Bjorn Engsig, Alexander Forst, Jeff Francis, Dave Gillespie, Samuel
  632.   Goldstein, Alasdair Grant, Ron Guilmette, Doug Gwyn, Tony Hansen, Joe
  633.   Harrington, Guy Harris, Jos Horsmeier, Blair Houghton, Kirk Johnson,
  634. > Peter Klausler, Andrew Koenig, Tom Koenig, John Lauro, Felix Lee, Don
  635. > Libes, Christopher Lott, Tim McDaniel, John R. MacMillan, Evan Manning,
  636. > Barry Margolin, Brad Mears, Mark Moraes, Darren Morby, Landon Curt Noll,
  637. > David O'Brien, Richard A. O'Keefe, Hans Olsson, Francois Pinard, Pat
  638. > Rankin, Erkki Ruohtula, Rich Salz, Chip Salzenberg, Paul Sand, Doug
  639.   Schmidt, Patricia Shanahan, Peter da Silva, Joshua Simons, Henry
  640. > Spencer, David Spuler, Erik Talvola, Clarke Thatcher, Wayne Throop,
  641. > Chris Torek, Goran Uddeborg, Wietse Venema, Ed Vielmetti, Larry Virden,
  642. > Chris Volpe, Freek Wiedijk, Dave Wolverton, Mitch Wright, Conway Yee,
  643. > and Zhuo Zang, who have contributed, directly or indirectly, to this
  644.   article.  Special thanks to Karl Heuer, and particularly to Mark Brader,
  645.   who (to borrow a line from Steve Johnson) have goaded me beyond my
  646.   inclination, and occasionally beyond my endurance, in relentless pursuit
  647.   of a better FAQ list.
  648. ==========
  649.  
  650.                     Steve Summit
  651.                     scs@adam.mit.edu
  652.                     scs%adam.mit.edu@mit.edu
  653.                     mit-eddie!adam.mit.edu!scs
  654.