home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 19051 < prev    next >
Encoding:
Text File  |  1993-01-12  |  7.4 KB  |  153 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: <1993Jan12.204503.15692@microsoft.com>
  6. Date: 12 Jan 93 20:45:03 GMT
  7. Organization: Microsoft Corporation
  8. References: <1993Jan5.185023.3646@taumet.com> <1993Jan06.190203.5785@microsoft.com> <1993Jan8.040102.14651@cbnewsk.cb.att.com>
  9. Keywords: c++, ansi c
  10. Lines: 141
  11.  
  12. In article <1993Jan8.040102.14651@cbnewsk.cb.att.com> hansen@pegasus.att.com (Tony L. Hansen) writes:
  13. |As long as the C functions are permitted to be implemented as macros, it is
  14. |impossible to reliably overload any function name found in the C library.
  15.  
  16. This statement is incorrect.  A corrected statement would be:
  17.  
  18. As long as a given C function is permitted to be implemented as a macro, it is
  19. impossible to reliably overload that function name found in that C library
  20. if you include the header file for that C library.  However, if you DO NOT
  21. include that header file, it is indeed possible to reliably overload any
  22. function name.
  23.  
  24. Note two things:  You try to argue the general from the specific.
  25. This is not and all-or-nothing decision and should not be treated as 
  26. such.  Some ANSI-C function names could be required to be non-macro,
  27. some could be required to be out-of-line, some could even be required to
  28. be declared inline, and some could remain macro implemented as called-out
  29. by ANSI-C.
  30.  
  31. Secondly, note that there IS a simple solution that allows BOTH overloading
  32. and maintaining the requirements of ANSI-C.  Namely: simply do not include
  33. the ANSI-C header file.  If you do not include the header file, then 
  34. you do not get any possible macro implementations.  This further allows
  35. the possibility that ANSI-C++ define differently named header files,
  36. such header files implementing ANSI-C header file functionality, but
  37. in a guaranteed non-macro manner.  For example, ANSI-C++ could simply
  38. declare that the equivalent C++ header files have an .hpp extension,
  39. said extension implying non-macro implementations, whereas if a programmer
  40. continues to use the file with the .h extension, the programmer continues
  41. to get the behavior permitted by the ANSI-C base document.
  42.  
  43. |    complex sqrt(complex&);
  44.  
  45. sqrt is one of my claimed handful of functions that have "attractive"
  46. names that should be returned to the programmer's name space.  .
  47. Excepting one can easily imagine that implementations should be
  48. allowed to provide float, double, long double, complex, int, short, 
  49. unsigned .... versions of this function.  Again, what you give to the
  50. programmer you deny the implementor, so you better think about these
  51. things on a per function basis, rather than just making a blanket statement
  52. returning these names to the programmer space.
  53.  
  54. |Do you think it's reasonable to be able to overload functions such as
  55. |fprintf() and rewind() for a type such as "File" instead of "FILE"?
  56.  
  57. "Rewind" is another one of the attractive names.  fprintf is unreasonable
  58. for a C++ programmer.  You are arguing that the C++ programmer should
  59. implement classes with one foot in the present and one foot in the past.
  60. I disagree.  C++ programmers ought to implement new classes using C++
  61. style and capabilities.
  62.  
  63. The unsafe and ugly C:
  64.  
  65.     fprintf(pfile, "format", varargs)
  66.  
  67. becomes:
  68.  
  69.     file << arg1 << arg2 << arg3;
  70.  
  71. to a reasonable C++ programmer.
  72.  
  73. | How
  74. |about a function such as the string functions which all start with str*?
  75. |Would you like to be able to overload those for a String class? 
  76.  
  77. No.  I would like a reasonably defined standard String class so that
  78. I can avoid using all those functions [actually frequently compiler 
  79. intrinsics] that start with str.  Leave the compiler writers their
  80. intrinsic functions.  They built them into their compiler because
  81. these names were guaranteed them by ANSI-C.
  82.  
  83. |overloading qsort() or bsearch() as template functions which work on an
  84. |array of T instead of a void* memory area? 
  85.  
  86. Are you trying to tell me that implementations have implemented these
  87. things as macros?  If not, then where is your argument?  They are not
  88. macros, have not been, and thus do not represent an issue.
  89.  
  90. |Or how about overloading the time
  91. |functions, such as difftime() and time(), for a Time class?
  92.  
  93. time() is essentially the ctor for the ANSI-C "time" [actually time_t] class.
  94. One cannot have function names be the same as a class name, because that
  95. name becomes reserved for the class and and its ctors.  This is nothing
  96. new, and is not a macro issue.  When you make your Time class, don't name
  97. it "time" but rather [god forbid] "Time" or something and there is no
  98. conflict.  Or alternately don't include the ANSI-C "time.h" header.
  99.  
  100. | How about
  101. |overloading the math functions, such as sin() and tan(), using a float
  102. |instead of a double?
  103.  
  104. Again, these are traditional "attractive" names that should be returned
  105. to the programmer.  Except clearly implementations should be allowed to
  106. overload to implement float and long double versions themselves.  Which
  107. raises the issue again:  When you return this name space to the programmer,
  108. you are denying it to the implementation.  How then can implementations
  109. implement these kinds of reasonable extensions?  Clearly a blanket return
  110. of these name spaces to the programmer is a WRONG decision!  Life is not
  111. so simple.!
  112.  
  113. |I think all of the above are within reasonable expectations. And guess what?
  114. |You've just covered over half of the list of ANSI C functions. And, as long
  115. |as the C functions are permitted to be implemented as macros, you won't be
  116. |able to overload any of them!
  117.  
  118. Again, a correct statement would be for any function permitted to be
  119. implemented as a macro, you would not be allowed to overload IFF you
  120. included the corresponding ANSI-C header file.  If you did not include
  121. that header file, you CAN overload.
  122.  
  123. Further, I count exactly nine functions you mention, which is nowhere
  124. near half of the ANSI-C library definitions.  Of those nine, I agree
  125. that you have identified two that can be reasonably overloaded.  Two
  126. ways that such overloading could be permitted would be to violate the
  127. ANSI-C base document obsolesence agreeement and simply prohibit macro
  128. implementations of these two functions, or alternatively require the
  129. programmer to not include the ANSI-C header files if they want to 
  130. overload these functions.
  131.  
  132. |I'm not willing to lose that capability.
  133.  
  134. You DO NOT LOSE that capability!  You CHOOSE that capability by including
  135. or not including the ANSI-C header file.  If you CHOOSE to include the 
  136. ANSI-C header file, then you should get a conforming ANSI-C implementation 
  137. of that header file as has been promised you and your compiler implementor.
  138. If you CHOOSE not to include the ANSI-C header file, then you can use
  139. those names any way you so desire.  If the ANSI-C++ committee cannot abide
  140. by the rules promised by the ANSI-C base document, a solution is for
  141. the ANSI-C++ committee to simply define their own uniquely named header
  142. files implementing the rules that THEY believe should apply.  There is
  143. no reason to break the ANSI-C header files and the rules called out for
  144. implementing those header files.  Again, the ANSI-C document calls out
  145. the rules for obsoleting an ANSI-C feature, and you guys are ignoring
  146. those rules.  If you cannot abide those rules, then do not call ANSI-C
  147. one of your base docs.
  148.  
  149. Finally, how about a counter-example:  Give me good reason why malloc
  150. should be required to be implemented in a non-macro manner, such that
  151. traditional debugging-malloc libraries can no longer be implemented?
  152.  
  153.