home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!brunix!brunix!sdm
- From: sdm@cs.brown.edu (Scott Meyers)
- Subject: Re: Zero-length structures and pointer comparisons
- Message-ID: <1992Sep10.153202.23881@cs.brown.edu>
- Sender: news@cs.brown.edu
- Organization: Brown University Department of Computer Science
- References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se> <1992Sep10.094957.23588@jyu.fi>
- Date: Thu, 10 Sep 1992 15:32:02 GMT
- Lines: 32
-
- In article <1992Sep10.094957.23588@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
- | In article <4945@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
- | >
- | >const T& operator = ( const T& t )
- | >{
- | > if ( &t == this ) return; // avoid self-assignment
- | > // ...
- | >}
- | >
- | >Is the above idiom broken?
- |
- | Oh dear, why have I not noted this _horrible_ defect in the language
- | definition before? Probably because it was too bad to be suspected.
- | The above idiom is certainly common, and it is used in Stroustrup's
- | own books. The first example I could found now in "The C++ P. L." (2. ed.)
- | is in 8.3.3 (p. 266).
-
- The idiom is clearly older than that. Stroustrup uses it in the FIRST
- edition of his book, section 6.6, p. 179:
-
- void String::operator=(String& a)
- {
- if (this == &a) return; // beware of s=s;
- ...
-
- It would certainly cause grief to many a program if this were to suddenly
- be found to be unportable.
-
- Scott
-
- -------------------------------------------------------------------------------
- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."
-