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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!att!cbnewsk!pegasus!hansen
  3. From: hansen@pegasus.att.com (Tony L. Hansen)
  4. Subject: Re: Standard library functions and macros
  5. Organization: AT&T
  6. Date: Fri, 8 Jan 1993 04:01:02 GMT
  7. Message-ID: <1993Jan8.040102.14651@cbnewsk.cb.att.com>
  8. Summary: cannot overload functions with macros present
  9. Keywords: c++, ansi c
  10. References: <1993Jan04.231519.8704@microsoft.com> <1993Jan5.185023.3646@taumet.com> <1993Jan06.190203.5785@microsoft.com>
  11. Sender: hansen@cbnewsk.cb.att.com (tony.l.hansen)
  12. Lines: 65
  13.  
  14. < From: jimad@microsoft.com (Jim Adcock)
  15. <
  16. < No, I do not disagree with this part of the decision.  I simply disagree
  17. < that it makes sense to return the vast majority of the standard functions
  18. < namespace to the programmer.  On the contrary I claim that the vast
  19. < majority of these names should remain in the implementation space, because
  20. < implementing them as macros, or providing alt implementations, as in the
  21. < Sun example, remain useful and viable options to the implementation.
  22. < Whereas the vast majority of the names in question represent deliberately
  23. < "decorated" or "mangled" names if you will that have little or no
  24. < applicability to the C++ programmer as useful member function names, or
  25. < even global names. So in the vast majority of cases your suggested changes
  26. < destroy utility on the implementor's side without corresponding increase
  27. < in utility on the programmer's side.  This is clearly a bad trade-off.
  28. < Again, if you want to go through the functions in a sensible manner, and
  29. < choose certain names such as "free" that have plausible utility to the end
  30. < programmer, and insist on non-macro and non-overloaded implementation of
  31. < these functions, such that the name-space remains available to the
  32. < programmer, then I would agree with such a thoughtful, well-considered,
  33. < measured approach.  I just disagree with the blanket changes that have
  34. < been proposed to date.
  35.  
  36. As long as the C functions are permitted to be implemented as macros, it is
  37. impossible to reliably overload any function name found in the C library.
  38.  
  39. For example, consider
  40.  
  41.     #include <math.h>
  42.     class complex ...
  43.     complex sqrt(complex&);
  44.  
  45. This looks pretty safe, right? Wrong!
  46.  
  47. Consider what happens with the following definition of sqrt() in <math.h>:
  48.  
  49.     #define sqrt(x)    __asm(push x; call sqrt;)
  50.  
  51. Oops, that safe looking declaration of sqrt(complex&) suddenly looks like
  52. this:
  53.  
  54.     complex push(complex&); call sqrt;
  55.  
  56. Not so pretty looking now, is it?
  57.  
  58. Do you think it's reasonable to be able to overload functions such as
  59. fprintf() and rewind() for a type such as "File" instead of "FILE"? How
  60. about a function such as the string functions which all start with str*?
  61. Would you like to be able to overload those for a String class? Or how about
  62. overloading qsort() or bsearch() as template functions which work on an
  63. array of T instead of a void* memory area? Or how about overloading the time
  64. functions, such as difftime() and time(), for a Time class? How about
  65. overloading the math functions, such as sin() and tan(), using a float
  66. instead of a double?
  67.  
  68. I think all of the above are within reasonable expectations. And guess what?
  69. You've just covered over half of the list of ANSI C functions. And, as long
  70. as the C functions are permitted to be implemented as macros, you won't be
  71. able to overload any of them!
  72.  
  73. I'm not willing to lose that capability.
  74.  
  75.                     Tony Hansen
  76.                 hansen@pegasus.att.com, tony@attmail.com
  77.                 att!pegasus!hansen, attmail!tony
  78.  
  79.