home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1945 < prev    next >
Encoding:
Text File  |  1993-01-01  |  3.2 KB  |  104 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Argument matching
  5. Message-ID: <1993Jan1.161813.1592@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec31.053242.3376@ucc.su.OZ.AU> <1992Dec31.170854.21696@lpi.liant.com>
  10. Date: Fri, 1 Jan 1993 16:18:13 GMT
  11. Lines: 91
  12.  
  13. In article <1992Dec31.170854.21696@lpi.liant.com> pkt@lpi.liant.com (Scott Turner) writes:
  14. >In article <1992Dec31.053242.3376@ucc.su.OZ.AU>, maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >> Proposal: 
  16. >> 
  17. >> 1) for the purposes of computing the signature of a function,
  18. >> the symbols 'const', 'volatile' and any trailing '&' are ignored.
  19. >
  20. >> 2) As usually, attempting to define two functions with the same
  21. >> signature results in a duplicate defintion.
  22. >
  23. >The worst effect of this idea would be that
  24. >
  25. >    void f(int&)
  26. >and    void f(const int&)
  27. >
  28. >could not be overloaded.  This is useful and I don't think bad design.
  29.  
  30.     However, it *is* the intention of the proposal as it stands.
  31. Similarly,
  32.  
  33.     f(int*);
  34.     f(const int*);
  35.  
  36. would not both be allowed. The argument in favour of this
  37. is that overloading is for two purposes:
  38.  
  39. A)    families of semantically equivalent operations on different types
  40.     e.g. sin(float), sin(complex)
  41.  
  42. B)    convenience for accidental overloading
  43.     e.g. draw(gun); draw(picture)
  44.     or   sin(float); sin(priest);
  45.  
  46. In case (A) overloading is desirable because the associated
  47. 'transparency' renders the program more readable and amenable
  48. to change of the types (float->complex). 
  49.  
  50. Addition of extra overloaded functions may cause re-binding,
  51. say sin(double) is added, but it doesnt really matter
  52. because this doesnt affect the overall semantics.
  53. (Just precision and efficiency in this case)
  54.  
  55. In case (B) it is hoped the context will supply sufficient
  56. context so that the reader does not imagine that the sin of
  57. a priest is mathematical.
  58.  
  59. In the case that two functions
  60.  
  61.     f(int&);
  62.     f(const int&);
  63.  
  64. are desired, their use in a program would be extremely sensitive
  65. to the exact nature of the actual arguments, and the consequences
  66. dramatically different. I would argue it is better style to have
  67. two functions with different names:
  68.  
  69.     func_f(const int&); // proper function
  70.     proc_f(int&);  // procedure--warning side effects!
  71.  
  72. and the loss of overloading is in fact desirable.
  73. In particular, if a program had the function:
  74.  
  75.     f(const int&);
  76.  
  77. and the function
  78.  
  79.     f(int&);
  80.  
  81. were added, the meaning of the program would change: the call
  82.  
  83.     f(i);
  84.  
  85. may suddenly allow 'i' to be modified yielding unexpected results.
  86.  
  87. The prinicpal disadvantage of disallowing overloading on int& and 
  88. const int& is I think restricted to their use in operators,
  89. since these are not conveniently renamed.
  90.  
  91. For named functions, why is transparency of semantically distinct
  92. functions desirable?
  93.  
  94. I also remain confused about
  95.  
  96.     f(const volatile int&);
  97.     f(volatile int&);
  98.  
  99. -- 
  100. ;----------------------------------------------------------------------
  101.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  102.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  103. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  104.