home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1147 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.5 KB  |  44 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!brunix!brunix!sdm
  3. From: sdm@cs.brown.edu (Scott Meyers)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Sep10.153202.23881@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. References: <9225302.22791@mulga.cs.mu.OZ.AU> <4945@holden.lulea.trab.se> <1992Sep10.094957.23588@jyu.fi>
  9. Date: Thu, 10 Sep 1992 15:32:02 GMT
  10. Lines: 32
  11.  
  12. In article <1992Sep10.094957.23588@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
  13. | In article <4945@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  14. | >
  15. | >const T& operator = ( const T& t )
  16. | >{
  17. | >    if ( &t == this ) return;    // avoid self-assignment
  18. | >    // ...
  19. | >}
  20. | >
  21. | >Is the above idiom broken?
  22. | Oh dear, why have I not noted this _horrible_ defect in the language
  23. | definition before?  Probably because it was too bad to be suspected.
  24. | The above idiom is certainly common, and it is used in Stroustrup's
  25. | own books.  The first example I could found now in "The C++ P. L." (2. ed.)
  26. | is in 8.3.3 (p. 266).
  27.  
  28. The idiom is clearly older than that.  Stroustrup uses it in the FIRST
  29. edition of his book, section 6.6, p. 179:
  30.  
  31.     void String::operator=(String& a)
  32.     {
  33.         if (this == &a) return;  // beware of s=s;
  34.         ...
  35.  
  36. It would certainly cause grief to many a program if this were to suddenly
  37. be found to be unportable.
  38.  
  39. Scott
  40.  
  41. -------------------------------------------------------------------------------
  42. What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."
  43.