home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18521 < prev    next >
Encoding:
Text File  |  1992-12-29  |  5.6 KB  |  117 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: <1992Dec29.213548.5661@microsoft.com>
  6. Date: 29 Dec 92 21:35:48 GMT
  7. Organization: Microsoft Corporation
  8. References: <BzFM01.CD@frumious.uucp> <1992Dec23.214139.24948@microsoft.com> <1992Dec25.014646.9364@lucid.com>
  9. Lines: 106
  10.  
  11. In article <1992Dec25.014646.9364@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
  12. |In article <1992Dec23.214139.24948@microsoft.com>, jimad@microsoft.com (Jim Adcock) writes:
  13. |
  14. ||> Yes, assuming by "the meaning" of a C program you mean "the intent
  15. ||> of the original C author."  For example, the original author can
  16. ||> do a '#undef putchar' with "the meaning" that in this compilation his/her
  17. ||> intent is that putchar be implemented out-of-line.  Under the proposed
  18. ||> required changes to C++ implementations, "the meaning" of the original
  19. ||> C author would be silently changed.  Thus someone porting this C program
  20. ||> to C++ finds [or worse, DOESN'T FIND!] that C++ silently changes the 
  21. ||> intent of the original author.
  22. ||> 
  23. |
  24. |There is no such guarantee in standard C.  If there is a #include <stdio.h>
  25. |present, a compiler is free to inline putchar whether or not the user
  26. |does #undef putchar.  The constraint is in the other direction.  A
  27. |programmer can't use "putchar" in specific ways unless an #undef appears.
  28.  
  29. On the contrary, standard C DOES guarantee implementors the right
  30. to implement standard functions as macros, DOES guarantee that 
  31. programmers can get to a guaranteed underlying actual function
  32. call implementation of the standard functions, and DOES guarantee that the 
  33. #undef will get the programmer to the function call implementation.
  34.  
  35. See ANSI X3.159-1989 4.1.6
  36.  
  37. The fact that macro implementations are allowed under ANSI reserves the
  38. entirety of the name space of a standard function to the library if
  39. the header is included.  If the programmer doesn't like this, then
  40. the programmer is permitted to simply declare the function required
  41. out of the standard library, and just use that.  Which your changes
  42. will also break.
  43.  
  44. It seems pretty silly to think that ANSI-C++ can at this late
  45. date attempt to take the largest portion of the standard functions
  46. name space back away from the implementors without having negative
  47. consequences to conforming programs.
  48.  
  49. |If Jim is saying that in a particular implementation the #undef has
  50. |this effect and believes that effect should be preserved, then nothing
  51. |stops an implementation from giving the #undef the same effect in C++,
  52. |although I suspect he will have to lobby his vendors very hard to
  53. |convince them to implement such a feature.
  54.  
  55. If this is possible, then show me how to do it, because the solution
  56. is not obvious to me.
  57.  
  58. ||> Also, note that a conforming C implementation of these standard library
  59. ||> functions using macros can accept a superset of the parm types that a
  60. ||> C++ extern implementation or inline implementation can accept.  A macro
  61. ||> implementation is somewhat analogous to the C++ situation where a 
  62. ||> templated function is used.  Thus, requiring that a macro *not* be
  63. ||> used for implementation requires that some possible conforming programs
  64. ||> will no longer be accepted.  Still, breaking such a program is a MUCH better
  65. ||> situation that silently accepting a program while changing "the meaning" 
  66. ||> of that program.
  67. ||> 
  68. |
  69. |I'm not sure I understand this.  Is the intented example that 
  70. |there might be something like
  71. |
  72. |    #define putchar __myputchar
  73. |
  74. |And __myputchar would then be callable in different ways?   
  75.  
  76. No, the intended example would be if a macro-defined putchar were
  77. called with a parm not of char [actually int] type.  My claim is that
  78. a conforming implementation can have a macro-definition that accepts
  79. a superset of the parms that are strictly required to be accepted.
  80.  
  81. This might argue that it would be good to allow implementors to 
  82. use multiple inlines for some standard C library calls, such that
  83. those inlines are optimal for a given parm type.  Or that templated
  84. versions of some of the C standard functions could be appropriate.
  85. But in these cases the entirety of the name space would remain to
  86. the implementor, not to the programmer.  The problem lies with
  87. the fact that now, at this late date, you guys are trying to take
  88. part of the name space back from the implementor returning it to the
  89. programmer to do with as they will.  This is certain to break things.
  90.  
  91. ||> The other side of the coin is that it then becomes impossible for
  92. ||> programmers to specify *whether or not* they want an inline implementation,
  93. ||> which is a stated intent of the original ANSI-C standard library 
  94. ||> macro/function implementations.
  95. ||> 
  96. |
  97. |I've never seen such an intent expressed.  Where is it stated?
  98.  
  99. See ANSI X3.159-1989 4.1.6
  100.  
  101. |Contrary to the way Jim uses the word, I don't consider
  102. |whether a compiler inlines calls to a library function
  103. |part of the "meaning" of that function.  And neither
  104. |as far as I can tell does the standard.
  105.  
  106. I said the "meaning" of a programmer's PROGRAM would be silently changed,
  107. not that the "meaning" of the function would be silently changed.  You
  108. guys are REQUIRING implementors to break existing contracts between
  109. implementations and conforming programs expecting those implementations.
  110. Making these silent changes are not a trivial matter, and needed to be
  111. reconsidered in a serious manner.  
  112.  
  113. Again, I suggest that unless you have a very serious reason for requiring
  114. changes to existing standard C libraries, leave well enough alone.  There is 
  115. no reason why you have to mess with the historically reserved C name
  116. space and its implementation.
  117.