home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18686 < prev    next >
Encoding:
Text File  |  1993-01-04  |  6.7 KB  |  142 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Standard library functions and macros
  5. Message-ID: <1993Jan04.224604.7304@microsoft.com>
  6. Date: 04 Jan 93 22:46:04 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec25.014646.9364@lucid.com> <1992Dec29.213548.5661@microsoft.com> <9300302.725@mulga.cs.mu.OZ.AU>
  9. Lines: 131
  10.  
  11. In article <9300302.725@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  12. |I would be surprised if the changes did not require "real" external functions
  13. |"shadowing" the inline definitions just as ANSI C required real functions
  14. |to shadow macro definitions. 
  15.  
  16. It wouldn't be a conforming implementation if it provided both inline
  17. and out-of-line implementation of a function.  That would violate
  18. the one-definition rule.
  19.  
  20. |I think that perhaps you are overreacting a
  21. |little, Jim. 
  22.  
  23. That depends on one's point of view.  If one truly claims that ANSI-C
  24. is a base doc for the ANSI-C++ effort, then I don't think I'm overreacting
  25. when the ANSI-C++ committee redefines how the ANSI-C libraries work without
  26. having a conflicting overriding definition in the ARM.  If ANSI-C and ARM
  27. conflict, then by all means follow ARM, or otherwise resolve the conflict.
  28. But to ignore one of the base docs when no conflicts exist is to make
  29. a mockary of calling the thing a base doc.  There's a lot of good work
  30. in the ANSI-C base document, a lot of things have been well-defined in
  31. the ANSI-C that aren't defined at all in the ARM, and I'm afraid people are
  32. ignoring the ANSI-C work simply for the sake of N.I.H.  Which would be sad.
  33.  
  34. Whether I'm overreacting or not also depends on whether people consider
  35. it important to get programmers to switch from C to C++.  Every obstacle
  36. you put in their way gives them one more excuse to stay with C.  One
  37. obvious excuse is if C compiles their existing code more efficiently
  38. that C++.  Macros and intrinsics can still typically beat inlines.
  39. Another excuse is if they use 3rd party C libraries that are now 
  40. deemed incompatible with "standard" C++.
  41.  
  42. |>|If Jim is saying that in a particular implementation the #undef has
  43. |>|this effect and believes that effect should be preserved, then nothing
  44. |>|stops an implementation from giving the #undef the same effect in C++,
  45. |>|although I suspect he will have to lobby his vendors very hard to
  46. |>|convince them to implement such a feature.
  47. |>
  48. |>If this is possible, then show me how to do it, because the solution
  49. |>is not obvious to me.
  50. |
  51. |Step 1. Introduce a #pragma no-inline, eg.
  52. |
  53. |    #pragma no-inline putchar    // don't inline any function
  54. |                    // called putchar
  55. |
  56. |This should not pose much implementation difficulty.
  57. |(Many compilers already allow a #pragma which has the same effect but
  58. |works on all inline functions, rather than a particular one at a time.)
  59. |
  60. |Step 2. Ensure that if foo is not a macro, then
  61. |    #undef foo
  62. |has the same effect as
  63. |    #pragma no-inline foo
  64. |This should be even easier to implement.
  65.  
  66. Your "solution" does not implement the semantics called out in the ANSI-C
  67. spec.  If you read the ANSI-C spec, you will find other requirements on
  68. the ANSI-C library implementation that your "solution" does not support,
  69. such as selectively allowing out-of-line implementation on a per-function-call
  70. basis simply by enclosing the function name in parenthesis:
  71.  
  72.     (putchar)('\n');
  73.  
  74. |In the first case, the name would only be reserved
  75. |for use as an external identifier. Programmers could still use that
  76. |name for member functions, for example.
  77.  
  78. With only a handful of plausible exceptions, ANSI-C standard functions
  79. have "NO" applicability as member function names because they are
  80. *decorated* names.  If you want to make selective argument that some of
  81. the few non-decorated ANSI-C standard function names are so attractive
  82. that they ought to be returned to the programmer name space, so that
  83. these few exceptional, undecorated standard function names could be used
  84. as member functions, THEN I would agree with you.  I just don't buy the
  85. blanket argument that ALL the standard C functions ought to be returned
  86. to the programmer name space.  Because the vast majority of the standard
  87. function names are *decorated* -- as in fputc means "file-put-character"
  88. and such manually mangled names have no reasonable use to C++ programmers
  89. as member function names in any case.
  90.  
  91. As an example of a standard C function name that is so "attractive" that
  92. it out to be returned to C++ programmer space consider "free".  This name
  93. should have never been taken by the standard library in the first place.
  94. It should have been a decorated name, such a "mfree" to make it symmetric
  95. with the decorated malloc "memory-allocate" routine.  So if you 
  96. want to selectively argue that a few of the standard-C functions should require
  97. implementation as inlines so as to not take the whole name space away
  98. from the programmer, then I agree.  All standard C functions in this
  99. category?  No way!  Functions such as fputc would be very highly silly
  100. member functions!
  101.  
  102. |I disagree. The pure namespace generally occurs only if you invoke the
  103. |compiler with the pure ANSI flag (well, this is true of both of the lines
  104. |of C++ compilers that I have any experience with). 
  105.  
  106. The ANSI-C standard makes it clear that the presence or lack of a 
  107. "pure ANSI" flag in any otherwise conforming C compiler has nothing to
  108. do with the ANSI-C language, but rather is an implementation detail.
  109. As such these flags or lack thereof have nothing to do with this argument.
  110.  
  111. |>Again, I suggest that unless you have a very serious reason for requiring
  112. |>changes to existing standard C libraries, leave well enough alone.
  113. |
  114. |They do.
  115.  
  116. Then they should state their reasons.  To date all that has been stated
  117. for this blanket change to the base document is to return the name
  118. space of the standard-C functions to the programmer.  Yet read the
  119. ANSI-C standard and it becomes very clear that only a tiny handful of
  120. these functions make sense as function-names to put in the C++ programmer's
  121. name space.  If you want to intelligently and selectively decide to return
  122. these handful of functions to the C++ programmer's name space, then I
  123. support your efforts.  It's just that no good argument has been made
  124. for returning the vast majority [the "decorated" names] to the C++
  125. programmer.  The C++ programmer would be ill-advised to use such decorated
  126. names, because C++ already has its own *automatic* name mangling scheme.
  127. The C++ programmer can say:
  128.  
  129.     file.put('\n');
  130.  
  131. There is no good reason for the C++ programmer to say:
  132.  
  133.     file.fputc('\n');
  134.  
  135. since both the 'f' and the 'c' in "fputc" represent redundant manual
  136. name mangling -- the programmer would be manually duplicating the efforts
  137. that the compiler already supplies.  Such would simply be encouraging
  138. bad C++ practice at the expense of prohibiting good C practice.  Which
  139. is a lose-lose situation.
  140.  
  141.  
  142.