home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18780 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.4 KB  |  60 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: assert
  5. Message-ID: <1992Dec22.163928.10225@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <HBF.92Dec19163113@gandalf.uio.no> <1992Dec21.163006.8068@taumet.com> <9212211543.PN29748@LL.MIT.EDU>
  8. Date: Tue, 22 Dec 1992 16:39:28 GMT
  9. Lines: 49
  10.  
  11. lebrun@ll.mit.edu (Steven F. LeBrun) writes:
  12.  
  13.  
  14. >>    The first alternative (#include <stdio.h>) is forbidden by the C
  15. >>    Standard (standard headers may not #include other standard headers).
  16. >                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  17.  
  18. >I took a look at the ANSI C document (X3.159-1989) and could not find a
  19. >section that states that standard header files cannot include other
  20. >standard header files.  As a matter of fact, section 4.11.2 "Standard
  21. >Headers" states that header files included in any order and may be 
  22. >included more than once with the same effect as if they were included
  23. >only once.  [There is an exception pointed out in this section about
  24. >the <assert.h> header file.]
  25.  
  26. Taking the last first, a *program* may include the standard headers
  27. in any order and any number of times.  This is not a license for
  28. the *implementation* to do so.
  29.  
  30. There is no one sentence in the Standard which says that the standard
  31. headers may not include one another, but it is an unescapeable
  32. conclusion of ANSI section 4.1.2.1 (ISO 7.1.2.1), "Reserved Identifiers".
  33.  
  34. Let's take a simple example to see why.  If I do not include <stdarg.h>
  35. in my program, the identifier va_start is not reserved, and I may use
  36. it in any way that I like.  The following complete program is strictly
  37. conforming:
  38.  
  39.     #include <stdlib.h> /* to get EXIT_SUCCESS */
  40.     #include <stdio.h>  /* to get printf */
  41.     int main()
  42.     {
  43.         int va_start = EXIT_SUCCESS;
  44.         printf("Hello\n");
  45.         return va_start;
  46.     }
  47.  
  48. A naive implementation might include <stdarg.h> in <stdio.h> so that
  49. it would be easier to declare the v*printf functions.  That would
  50. render this strictly-conforming program undefined.  Therefore, such an
  51. implementation does not conform to the Standard.  Similar examples exist
  52. for all the standard headers.
  53.  
  54. Instead, implementations must jump through a few hoops to get everything
  55. done properly.  You can read about this in more detail in the book
  56. "The Standard C Library" by P. J. Plauger, Prentice-Hall.
  57. -- 
  58.  
  59. Steve Clamage, TauMetric Corp, steve@taumet.com
  60.