home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 5072 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.4 KB

  1. Path: severus.mbfys.kun.nl!rhialto
  2. From: rhialto@mbfys.kun.nl (Olaf Seibert)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: x ^= y ^= x ^= y;
  5. Date: 8 Mar 1996 17:39:07 GMT
  6. Organization: University of Nijmegen, The Netherlands
  7. Distribution: world
  8. Message-ID: <4hprbr$b29@wn1.sci.kun.nl>
  9. References: <1286.6624T1439T237@cs.ruu.nl> <3Du8y*20g@yaps.rhein.de>         <3132C4BE.2D60@cs.ruu.nl> <4h3ivp$966@hasle.sn.no> <2099.6633T1231T2431@cs.ruu.nl> <4hie4f$978@wn1.sci.kun.nl> <1378.6639T1116T760@cs.ruu.nl>
  10. NNTP-Posting-Host: severus.mbfys.kun.nl
  11.  
  12. In <1378.6639T1116T760@cs.ruu.nl> wsldanke@cs.ruu.nl (Wessel Dankers) writes:
  13. >Hmmm. How about the C++ way,
  14. >x.operator^=(y.operator^=(x.operator^=(y));
  15. >That would introduce a sequence point, wouldn't it?
  16.  
  17. The C++ working paper from september does say this about it in
  18. 5.2.2  Function call [expr.call]:
  19.  
  20. | 8 The order of evaluation of arguments is unspecified.  All side effects
  21. |   of  argument  expressions  take effect before the function is entered.
  22. |   The order of evaluation of the postfix  expression  and  the  argument
  23. |   expression list is unspecified.
  24.  
  25.  
  26. This seems to be what you want. Unless ofcourse somewhere else
  27. exceptions are made for the built-in types (see below).
  28.  
  29. Paragraph 1 describes what a function call actually *is*:
  30.  
  31. | 1 There are two kinds of function call: ordinary function call and  mem-
  32. |   ber function3) (_class.mfct_) call.  A  function  call  is  a  postfix
  33. |   expression followed by parentheses containing a possibly empty, comma-
  34. |   separated list of expressions which constitute the  arguments  to  the
  35. |   function.  For ordinary function call, the postfix expression shall be
  36. |   a function name, or shall have pointer  or  reference  to  a  function
  37. |   type.   For  member  function call, the postfix expression shall be an
  38. |   implicit (_class.mfct.nonstatic_, _class.static_)  or  explicit  class
  39. |   member  access  (_expr.ref_)  whose id-expression is a function member
  40. |   name, or a pointer-to-member expression (_expr.mptr.oper_) selecting a
  41. |   function  member.   The  first expression in the postfix expression is
  42. |   then called the object expression, and the call is as a member of  the
  43. |   object  pointed  to  or referred to.  In the case of an implicit class
  44. |   member access, the implied object is  the  one  pointed  to  by  this.
  45. |   [Note:  a  member  function  call  of  the  form f() is interpreted as
  46. |   (*this).f() (see _class.mfct.nonstatic_).  ] If a function  or  member
  47. |   function  name  is used, the name can be overloaded (_over_), in which
  48. |   case the appropriate function shall be selected according to the rules
  49. |   _________________________
  50. |   3)  A static member function (_class.static_) is an ordinary function.
  51. |   in  _over.match_.   The  function  called in a member function call is
  52. |   normally selected according to the static type of the  object  expres-
  53. |   sion  (see _class.derived_), but if that function is virtual the func-
  54. |   tion actually called will be the final overrider (_class.virtual_)  of
  55. |   the  selected  function  in  the dynamic type of the object expression
  56. |   [Note: the type of the object pointed or referred to  by  the  current
  57. |   value  of  the  object expression.  Clause _class.cdtor_ describes the
  58. |   behavior of virtual function calls when the  object-expression  refers
  59. |   to an object under construction or destruction.  ]
  60.  
  61. |   ______________________________________________________________________
  62. |   5   Expressions                                       [expr]
  63. |   ______________________________________________________________________
  64. | 1 [Note: this clause defines the syntax, order of evaluation, and  mean-
  65. |   ing  of  expressions.   An  expression  is a sequence of operators and
  66. |   operands that specifies a computation.  An expression can result in  a
  67. |   value and can cause side effects.
  68. | 2 Operators  can  be  overloaded, that is, given meaning when applied to
  69. |   expressions of class type (_class_).  Uses of overloaded operators are
  70. |   transformed  into  function  calls as described in _over.oper_.  Over-
  71. |   loaded operators obey the rules for syntax specified in  this  clause,
  72. |   but the requirements of operand type, lvalue, and evaluation order are
  73. |   replaced by the rules for function call.  Relations between operators,
  74. |   such  as ++a meaning a+=1, are not guaranteed for overloaded operators
  75. |   (_over.oper_), and are not  guaranteed  for  operands  of  type  bool.
  76. |   [Example: the left operand of += must not have type bool.  ] ]
  77. | 3 This clause defines the operators when applied to types for which they
  78. |   have not been overloaded.  Operator overloading shall not  modify  the
  79. |   rules  for  the  built-in operators, that is, for operators applied to
  80. |   types for which they are defined by  the  language  itself.   However,
  81. |   these  built-in  operators  participate  in  overload  resolution; see
  82. |   _over.match.oper_.
  83. | 4 Except where noted, the order of evaluation of operands of  individual
  84. |   operators  and subexpressions of individual expressions, and the order
  85. |   in which side effects take place, is unspecified.  Between the  previ-
  86. |   ous  and  next  sequence  point  a scalar object shall have its stored
  87. |   value modified at most once by the evaluation of an expression.   Fur-
  88. |   thermore,  the  prior  value  shall  be accessed only to determine the
  89. |   value to be stored.  The requirements of this paragraph shall  be  met
  90. |   for  each  allowable  ordering of the subexpressions of a full expres-
  91. |   sion; otherwise the behavior is undefined.  [Example:
  92. |           i = v[i++];      // the behavior is undefined
  93. |           i = 7,i++,i++;   // `i' becomes 9
  94. |           i = ++i + 1;     // the behavior is undefined
  95. |           i = i + 1;       // the value of 'i' is incremented
  96. |    --end example]
  97.  
  98. I think that in the above, "Overloaded operators obey the rules for
  99. syntax specified in  this  clause, but the requirements of operand
  100. type, lvalue, and evaluation order are replaced by the rules for
  101. function call." means that built-in operators are not function calls
  102. (even if you write them as such), because they are not overloaded. In
  103. other words: even your rather extreme example would not do what you
  104. want.
  105.  
  106. I find the C standard much easier to read...
  107.  
  108. >Wessel Dankers                 _\\|//_            <wsldanke@cs.ruu.nl>
  109. -Olaf.
  110. --
  111. ___ Olaf 'Rhialto' Seibert      rhialto@mbfys.kun.nl      The only excuse
  112. \X/    for making a useless thing is that one admires it intensely. -O.W.
  113.