home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / cplus / 920 < prev    next >
Encoding:
Text File  |  1992-07-22  |  9.2 KB  |  226 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Alternatives to operator.()
  5. Message-ID: <1992Jul23.024159.18039@microsoft.com>
  6. Date: 23 Jul 92 02:41:59 GMT
  7. Organization: Microsoft Corporation
  8. References: <BrM3LI.CBo@world.std.com> <1992Jul20.235728.29058@microsoft.com> <Brqq7D.97w@world.std.com>
  9. Lines: 215
  10.  
  11. In article <Brqq7D.97w@world.std.com> wmm@world.std.com (William M Miller) writes:
  12. |Yes, I've read your "answers" (see, I can use the quote key, too --
  13. |can we agree to stop casting aspersions on the validity of one
  14. |another's mental processes and just deal with the issues
  15. |dispassionately?).  
  16.  
  17. This would require some understanding and memory retention of my prior
  18. statements on your part so that I do not have to keep repeatedly answering
  19. your same mistakes made over and over again.
  20.  
  21. |The reason I listed my objections here was to
  22. |demonstrate that none of them were comparative, not to elicit further
  23. |discussion of them.
  24.  
  25. Yet when your objections are stated in error, then I have to further
  26. discuss them.  Whereas if you read and understood my corrections to
  27. your erroneous objections, and retracted those erroneous objections, 
  28. then we could go on to something more constructive.
  29.  
  30. |is.  So is "::".  I contend that "." is more like "::" than like "->".
  31.  
  32. I have addressed this argument previously.  Built-in operator-> means
  33. the same as "(*ptr)." thus if the "." performs no action then *ptr and
  34. ptr-> should have the same action.  BUT, the language already allows
  35. operator*() and operator->() to be overloaded independently, resulting
  36. in DIFFERENT actions.  So, the EXISTING C++ LANGUAGE DEFINITION contradicts
  37. your position.  To make your position defendable, overloadable operator->() 
  38. would have to be removed from the language, leaving operator->() to ALWAYS 
  39. have the built-in equivalence "(*ptr)."  In which case the actions of -> and .
  40. would always be consistent.  BUT, given that operator->() CAN be overloaded,
  41. the operator.() MUST be overloadable too, so that the relationship
  42. "ptr->" <==> "(*ptr)." can be maintained by the programmer.
  43.  
  44. ------
  45.  
  46. Your mis-statements below simply reflect a fundamental misunderstanding
  47. of the language and how it works:
  48.  
  49. |    struct X { int i; };
  50. |
  51. |    int i;
  52. |
  53. |    void f() {
  54. |        int i;
  55. |        X x;
  56. |        X* xp;
  57. |        X& xr = x;
  58. |
  59. |        // reference expression
  60. |
  61. |    }
  62. |
  63. |Consider each of the following expressions at the location indicated
  64. |by the comment "reference expression":
  65. |
  66. |    Expression    Interpretation
  67. |    ----------    --------------
  68. |
  69. |    i        Fetch the value at the appropriate offset in
  70. |            f()'s stack frame
  71.  
  72. Plain Wrong.  The expression "i" at this location means "reference to the object
  73. named by i".  Your interpretation is simply in error, as can be seen
  74. by using your expression "i" as follows:
  75.  
  76.     i = 5;
  77.  
  78. If "i" means "Fetch the value...." then one value is being assigned to
  79. another value, which simply does not make sense.  Under your interpretation
  80. then, "i = 5" would have to be a compiler error.
  81.  
  82. |    ::i        Fetch the value at the appropriate offset in
  83. |            the program's static storage region
  84.  
  85. Plain Wrong.  The expression "::i" at this location means "reference to the 
  86. object named by ::i".  Your interpretation is simply in error, as can be seen
  87. by using your expression "::i" as follows:
  88.  
  89.     ::i = 5;
  90.  
  91. If "::i" means "Fetch the value...." then one value is being assigned to
  92. another value, which simply does not make sense.  Under your interpretation
  93. then, "::i = 5" would have to be a compiler error.
  94.  
  95. |    x.i        Fetch the value at the appropriate offset in
  96. |            the object "x"
  97.  
  98. Plain Wrong.  The expression "x.i" at this location means "reference to the 
  99. object named by 'x.i'".  Your interpretation is simply in error, as can be seen
  100. by using your expression "x.i" as follows:
  101.  
  102.     x.i = 5;
  103.  
  104. If "x.i" means "Fetch the value...." then one value is being assigned to
  105. another value, which simply does not make sense.  Under your interpretation
  106. then, "x.i = 5" would have to be a compiler error.
  107.  
  108. LIKEWISE the expression "x" must itself be a reference.  "." applied
  109. to this reference "dereferences" it to get to the specified referenced
  110. member.
  111.  
  112. |    (*xp).i        Fetch the value at the appropriate offset in
  113. |            the object found by indirecting through the
  114. |            value of "xp"
  115.  
  116. Wrong, same reasons.
  117.  
  118. |    xp->i        Fetch the value at the appropriate offset in
  119. |            the object found by indirecting through the
  120. |            value of "xp"
  121.  
  122. Wrong, same reasons.
  123.  
  124. |    xr.i        Fetch the value at the appropriate offset in
  125. |            the object to which "xr" refers, i.e., "x"
  126.  
  127. Wrong, same reasons.
  128.  
  129. |Notice that each of these interpretations begins with the same phrase,
  130. |regardless of the presence or absence of "." in the expression.  
  131.  
  132. Agreed, its just that in every case you use the wrong phrase, and
  133. thereby in every case come to the wrong conclusions.  Whereas if you
  134. understood the language correctly, you would come to the right conclusions.
  135.  
  136. |The only difference is the context in which the offset is applied.  In two
  137. |of the cases, (*xp).i and xp->i, there is an explicit indirection,
  138. |which is the overloadable operation.  In the case of "xr.i" there is
  139. |deliberate ambiguity as to whether an indirection occurs; a reference
  140. |may be, but need not be, implemented by a pointer.
  141.  
  142. On the contrary, if your phrases above were correct, you would find
  143. that in all cases an indirection occurs.  Its just that in some built-in
  144. cases the compiler is smart enough to commonly optimize out the indirection.
  145.  
  146. |The point of this exercise was to demonstrate that, semantically, the
  147. |builtin "." only provides qualification for the right hand side --
  148. |i.e., an addressing context and a scope in which the right hand side
  149. |can be looked up to determine "the appropriate offset" for the
  150. |interpretation.  This is exactly what "::" -- or even the absence of
  151. |qualification -- does.  I don't imagine this analysis will convince
  152. |you. 
  153.  
  154. It can't convince me because quite simply it is in error, as noted above.
  155.  
  156. |but perhaps you can at least acknowledge that this interpretation
  157. |of builtin "." is simple and self-consistent. 
  158.  
  159. It is simple -- simple and erroneous.  It is not consistent, because
  160. it differs with the actual behavior of the language.  Again, when the
  161. language sees an expression "i" it must interpret this expressions as
  162. "reference to an object".  The language cannot use different
  163. interpretations of the expression "i" depending on LHS verses RHS context
  164. because expressions in C/C++ do not depend on context.
  165.  
  166. | To my mind, this "objection" -- that "." isn't like the overloadable 
  167. |operators -- still stands.
  168.  
  169. Correct your erroneous mind's understanding of the language, then your erroneous
  170. "objection" falls too.
  171.  
  172. |> My operator.() proposal DOES NOT require forwarding functions unless
  173. |> the implementor of the reference class DESIRES to use forwarding functions.
  174. |
  175. |But the same can be said of the current situation -- you only have to
  176. |provide forwarding functions for those features of the target class
  177. |you desire to use.  The "objection" still stands.
  178.  
  179. You can say this -- because as time has show there is no way I can prevent
  180. you from saying erroneous statements.  Your statement is false.  One 
  181. DOES NOT have to provide forwarding functions for those features of the 
  182. target class one desires to use.  On the Contrary one can CHOOSE to provide
  183. forwarding functions if desired.  If NOT desired, then operator.() can
  184. be used to forward enmasse the target class functions requiring a target
  185. class object as an LHS, and "operator targetclass()" can be used for
  186. forward enmasse the target class functionality not requiring a target
  187. class object as an LHS, and within the Smart Ref class no forwarding
  188. functions are necessary because of implied this.
  189.  
  190. Correct your errors and your objections do not continue to stand.
  191.  
  192. |This is the same sort of semantic dancing as the previous point; the
  193. |fact is that, under your proposal, you must use a circumlocution to
  194. |access members of the smart reference object.  The "objection" still
  195. |stands.
  196.  
  197. Your statement is false again.  No circumlocution is necessary because
  198. of "implied this."  Correct your errors and your objection does not stand.
  199.  
  200. |Thanks for your concern; my facts are in pretty good shape.
  201.  
  202. If "facts" need not have any basis in reality, then they are indeed in
  203. "pretty good shape" because there is no way that such "facts" can be
  204. challenged.
  205.  
  206. |That's not what I said.  What I said was that the two alternatives I
  207. |mentioned did not have these three particular disadvantages of your
  208. |proposal but that I had not fully explored them.  
  209.  
  210. You also need to explore my proposal, so that you can discover that in
  211. fact the particular disadvantages you mention are not in fact disadvantages
  212. of my proposal, but rather errors in understanding on your part.
  213.  
  214. |They may, in fact,
  215. |have far worse disadvantages than your proposal 
  216.  
  217. The most common disadvantage of these "other" approaches people have 
  218. "thought" about is that simply they have no basis in the reality of
  219. the existing language.  If one understands the language, and tries
  220. to write down how most of these "thoughts" would work, you simply find
  221. that they cannot work, given the context of the existing language, and
  222. how that existing language works.  Languages and compilers aren't magic, 
  223. "thoughts" people think up have to be implementable in the current context
  224. of how the language and compilers work.  My proposal at least has the
  225. advantage that it can be so implemented.
  226.