home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3292 < prev    next >
Encoding:
Text File  |  1992-12-30  |  5.7 KB  |  114 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Maximum depth of #if preprocessing directives
  5. Message-ID: <1992Dec30.184909.23125@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <JET.92Dec24133237@boxer.nas.nasa.gov> <BzsK12.5Ky@jrd.dec.com> <1992Dec29.001933.25655@lucid.com> <C01q3x.Bpp@sneaky.lonestar.org>
  8. Date: Wed, 30 Dec 1992 18:49:09 GMT
  9. Lines: 103
  10.  
  11. gordon@sneaky.lonestar.org (Gordon Burditt) writes:
  12.  
  13. [ Jerry Schwarz writes: ]
  14. >>Just to put my cards on the table.  X3J16/SC22 (C++ standards
  15. >>committee) is sharply divided on whether to have a section on
  16. >>limits.  Some of us, including myself, argue that without such
  17. >>a section any limit is a bug. With such a section arbitrary limits
  18. >>are somehow condoned as suggested by Norman's comment, and we
  19. >>don't want to condone any limits.
  20.  
  21. >How can you possibly avoid some kind of limit?  Even an implementation
  22. >that uses arbitrary-precision arithmetic for something such as
  23. >#if nesting level is going to have SOME limit, like 
  24. >2^(MAXLONG*sizeof(unsigned long)*CHAR_BIT) (where ^ is an exponentiation
  25. >operator), even if it's outrageously large.  
  26.  
  27. >Is 32767 an unreasonable limit on the nesting level?  Well, it wouldn't
  28. >cost that much to put the counts in a 32-bit long.  Do I need to go to 
  29. >(about) 2^(2^37)?  (about 137 billion bits in the number)  Or is that 
  30. >too small?
  31.  
  32. I share Jerry's position, that the Standard should not contain limits.
  33. Let me note that Jerry and I are each compiler implementors, and all our
  34. compilers (from different companies) easily exceed all the limits in the
  35. C Standard.  So we aren't writing out of fear that our compilers will
  36. become invalid.  We are concerned about the consequences to the C and
  37. C++ communities of limits in the Standard.  No other language standard
  38. imposes such limits.
  39.  
  40. I wrote a paper on this topic for the C++ Committee.  I can't go
  41. into all the details here, but let's consider nesting levels as an
  42. example.
  43.  
  44. Suppose the Standard says 8 levels.  Some programmers will need more
  45. than 8.  The compiler is not obligated to support more than 8, and if it
  46. doesn't, the user can only beg for more levels.  But since you can't
  47. depend on more than 8, you better not use more than 8 in any program
  48. which is supposed to be portable.  Many programming shops have rules
  49. that you can't write a program which violates any portability rules in
  50. the Standard.  In this way, the "minimum" in the Standard becomes a
  51. real-world "maximum" for programmers.  Programs which need more than 8
  52. levels have to be bent to conform to the limit, becoming harder to
  53. understand and maintain.
  54.  
  55. You can substitute any small integer for 8, or choose any other limit
  56. in the C standard, and get a similar situation.
  57.  
  58. Now let's make the limit 32767 for nested includes.  Surely no program
  59. will need more than that.  (Except for poor Pat, who desperately needs
  60. 32803, but Pat is out of luck.)  Most (all?) operating systems won't
  61. allow a program (the compiler) to open that many files simultaneously.
  62. This means the compiler has to have a mechanism to close and reopen
  63. files as needed, seeking to a remembered location, when the local limit
  64. on open files has been exceeded.  Sometimes the limit is system-wide,
  65. sometimes each process might have an individual limit; the compiler has
  66. to be able to figure out what the limit is or just have a fixed
  67. conservative limit.
  68.  
  69. Now we have imposed this elaborate mechanism on all compilers and all
  70. users, who have a bigger and slower compiler as a result.  Most users
  71. will never need so many nested includes, but they all pay the penalty.
  72.  
  73. Further, there may be some systems on which you can't have 32767 files
  74. at all.  Such a system cannot have a Standard-conforming compiler,
  75. since it can't pass the nested-include test.  The Standard will have
  76. disenfranchised small computer systems; only big systems can have a
  77. validated compiler.
  78.  
  79. Once again, substitute other numbers and other limits from the Standard
  80. to get similar situations.  Please don't point out that you can
  81. handle the above problem by clever coding and avoid penalties when
  82. the limits aren't exercised.  The overall impact is still to make
  83. compilers bigger and more complex if they must meet artificially
  84. large limits.
  85.  
  86. Now suppose that the Standard does not mention any limit on nested
  87. includes.  Every real compiler will have a limit of some kind.  If you
  88. need more than that, the compiler vendor can't hide behind the Standard.
  89. Failure to handle an #include is a bug.  One hopes that the vendor will
  90. make as many nested includes available as makes sense on the system.
  91. If you need more than are available, you can lobby the vendor, or find
  92. another one with more capacity.  A vendor who supplies a "conforming"
  93. implementation with only 1 level of include won't have any customers.
  94.  
  95. Some compiler implementations may find a niche by making small fast
  96. compilers of limited capacity which conform to all explicit requirements
  97. in the Standard.  You might choose the limited-capacity compiler if
  98. you are programming a small system.  The compiler can be validated,
  99. and you can expect your conforming code to work.
  100.  
  101. When choosing a compiler, there are many things you need to consider.
  102. If you are programming a large system, you need a compiler with large
  103. limits, no matter what the Standard says.  A conforming compiler which
  104. does not meet your needs is of no use.  If you are programming a small
  105. system, you don't care about limits, but you will want a conforming
  106. compiler nontheless.
  107.  
  108. I favor listing characteristics which a conforming implementation is
  109. required to document.  Just like choosing any other program, you could
  110. then choose a compiler which meets your needs.
  111. -- 
  112.  
  113. Steve Clamage, TauMetric Corp, steve@taumet.com
  114.