πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #143

Re: Answers on a postcard

#143
From: Karl Keyte
Date: Fri, 11 Sep 1992 14:42
49 lines
2183 bytes
...from a posting on 'comp.lang.c++'

In article <1992Sep10.174914.838@taumet.com>, steve@taumet.com (Steve Clamage)
says:
>
>Karl Keyte <KKEYTE@ESOC.BITNET> writes:
>
>|#include <iostream.h>
>
>|class X {
>|   private:    int           value;
>|   public:     int           operator , (int i) { return i+10; };
>|               int           operator + (int i) { return value+i; };
>|               X &           operator = (int i) { value=i; return *this; };
>|};
>
>
>|void main()
>|{
>|   X         x;
>
>|   cout << "Value is " << (x=1, x+1) << endl;
>|}
>
>In the expression in parens, it is unspecified whether "x=1" or
>"x+1" is evaluated first.  They are arguments to the "operator,()"
>function, not the left and right side of a comma-expression.  If
>"x+1" is evaluated first, which is legal, it will use an
>uninitialized "x.value".
>
>Don't write code which depends on unspecified order of evaluation.
>
>If there were no "op,()", the "," would mark a comma-expression,
>and the "x=1" would have to be evaluated first; in that case the
>whole expression would be well-defined.

The implication of what you say is that it is not possible to overload
operators maintaining the correct functionality of the operator.  This
indeed means that precedence in overloaded operators cannot be maintained
if all operands are simply passed as arguments to the function implementing
the operator functionality and evaluated in a language independent order.
Imagine commonly used "chain" operators such as && and ΒΊΒΊ.

If what is described above is correct, and Mr.Clamage clearly has much
experience in the area, then I think we have justification for pressing
for a change in this area.  If not, I would ask: How does one overload
the comma operator while maintaining its attibutes as an operator?

Karl
Technical Details
Message-ID: <92255.154216KKEYTE@ESOC.BITNET>
Path: arc1-ca.pugleaf.net!sparky!uunet!news.univie.ac.at!blekul11!frmop11!dearn!esoc!kkeyte

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!news.univie.ac.at!blekul11!frmop11!dearn!esoc!kkeyte
Organisation: European Space Operation Centre (E.S.O.C)
Date: Friday, 11 Sep 1992 15:42:16 CET
From: Karl Keyte <KKEYTE@ESOC.BITNET>
Message-ID: <92255.154216KKEYTE@ESOC.BITNET>
Newsgroups: comp.std.c++
Subject: Re: Answers on a postcard
Lines: 49