home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18633 < prev    next >
Encoding:
Text File  |  1993-01-02  |  5.9 KB  |  135 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Standard library functions and macros
  5. Message-ID: <9300302.725@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <BzFM01.CD@frumious.uucp> <1992Dec23.214139.24948@microsoft.com> <1992Dec25.014646.9364@lucid.com> <1992Dec29.213548.5661@microsoft.com>
  9. Date: Sat, 2 Jan 1993 15:22:04 GMT
  10. Lines: 123
  11.  
  12. jimad@microsoft.com (Jim Adcock) writes:
  13.  
  14. >jss@lucid.com (Jerry Schwarz) writes:
  15. >|jimad@microsoft.com (Jim Adcock) writes:
  16. >|
  17. >||> Yes, assuming by "the meaning" of a C program you mean "the intent
  18. >||> of the original C author."  For example, the original author can
  19. >||> do a '#undef putchar' with "the meaning" that in this compilation his/her
  20. >||> intent is that putchar be implemented out-of-line.  Under the proposed
  21. >||> required changes to C++ implementations, "the meaning" of the original
  22. >||> C author would be silently changed.  Thus someone porting this C program
  23. >||> to C++ finds [or worse, DOESN'T FIND!] that C++ silently changes the 
  24. >||> intent of the original author.
  25. >|
  26. >|There is no such guarantee in standard C.  If there is a #include <stdio.h>
  27. >|present, a compiler is free to inline putchar whether or not the user
  28. >|does #undef putchar.  The constraint is in the other direction.  A
  29. >|programmer can't use "putchar" in specific ways unless an #undef appears.
  30. >
  31. >On the contrary, standard C DOES guarantee implementors the right
  32. >to implement standard functions as macros,
  33.  
  34. Yes...
  35.  
  36. >DOES guarantee that 
  37. >programmers can get to a guaranteed underlying actual function
  38. >call implementation of the standard functions, and DOES guarantee that the 
  39. >#undef will get the programmer to the function call implementation.
  40.  
  41. I don't think this is the case - as Steve Clamage pointed out, the "as if"
  42. rule allows inline expansion despite the #undef.
  43.  
  44. >The fact that macro implementations are allowed under ANSI reserves the
  45. >entirety of the name space of a standard function to the library if
  46. >the header is included.  If the programmer doesn't like this, then
  47. >the programmer is permitted to simply declare the function required
  48. >out of the standard library, and just use that.  Which your changes
  49. >will also break.
  50.  
  51. I would be surprised if the changes did not require "real" external functions
  52. "shadowing" the inline definitions just as ANSI C required real functions
  53. to shadow macro definitions. I think that perhaps you are overreacting a
  54. little, Jim. Could someone who has actually read (or written ;-) the changes
  55. confirm that they would not break
  56.     extern char *puts(const char *);
  57.     inti main() { puts("Hello world\n"); return 0; }
  58. ?
  59.  
  60. >|If Jim is saying that in a particular implementation the #undef has
  61. >|this effect and believes that effect should be preserved, then nothing
  62. >|stops an implementation from giving the #undef the same effect in C++,
  63. >|although I suspect he will have to lobby his vendors very hard to
  64. >|convince them to implement such a feature.
  65. >
  66. >If this is possible, then show me how to do it, because the solution
  67. >is not obvious to me.
  68.  
  69. Step 1. Introduce a #pragma no-inline, eg.
  70.  
  71.     #pragma no-inline putchar    // don't inline any function
  72.                     // called putchar
  73.  
  74. This should not pose much implementation difficulty.
  75. (Many compilers already allow a #pragma which has the same effect but
  76. works on all inline functions, rather than a particular one at a time.)
  77.  
  78. Step 2. Ensure that if foo is not a macro, then
  79.     #undef foo
  80. has the same effect as
  81.     #pragma no-inline foo
  82. This should be even easier to implement.
  83.  
  84. >|I'm not sure I understand this.  Is the intented example that 
  85. >|there might be something like
  86. >|
  87. >|    #define putchar __myputchar
  88. >|
  89. >|And __myputchar would then be callable in different ways?   
  90. >
  91. >No, the intended example would be if a macro-defined putchar were
  92. >called with a parm not of char [actually int] type.  My claim is that
  93. >a conforming implementation can have a macro-definition that accepts
  94. >a superset of the parms that are strictly required to be accepted.
  95. >
  96. >This might argue that it would be good to allow implementors to 
  97. >use multiple inlines for some standard C library calls, such that
  98. >those inlines are optimal for a given parm type.  Or that templated
  99. >versions of some of the C standard functions could be appropriate.
  100. >But in these cases the entirety of the name space would remain to
  101. >the implementor, not to the programmer.
  102.  
  103. This is not correct. In the first case, the name would only be reserved
  104. for use as an external identifier. Programmers could still use that
  105. name for member functions, for example.
  106.  
  107. I think you could make a strong argument for allowing multiple inline
  108. implementations, in particular reserving the function name with any arguments
  109. that could be converted to the appropriate type by a standard
  110. conversion. I don't think you should allow templated versions.
  111.  
  112. >The problem lies with
  113. >the fact that now, at this late date, you guys are trying to take
  114. >part of the name space back from the implementor returning it to the
  115. >programmer to do with as they will.  This is certain to break things.
  116.  
  117. I disagree. The pure namespace generally occurs only if you invoke the
  118. compiler with the pure ANSI flag (well, this is true of both of the lines
  119. of C++ compilers that I have any experience with). Conforming but not
  120. strictly conforming programs might break if you compiled them with such
  121. a flag enabled, but why would you do so? Such programs often rely
  122. on additional functions which are declared in the standard headers
  123. when the pure ANSI flag is not enabled.
  124.  
  125. >Again, I suggest that unless you have a very serious reason for requiring
  126. >changes to existing standard C libraries, leave well enough alone.
  127.  
  128. They do.
  129.  
  130. -- 
  131. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  132. This .signature virus is a self-referential statement that is true - but 
  133. you will only be able to consistently believe it if you copy it to your own
  134. .signature file!
  135.