home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18176 < prev    next >
Encoding:
Text File  |  1992-12-20  |  1.9 KB  |  61 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!psinntp!cadkey!erics
  3. From: erics@cadkey.com (Eric Smith)
  4. Subject: Re: What is this CFRONT 3.0 warning message trying to tell me?
  5. Message-ID: <1992Dec17.184841.4563@cadkey.com>
  6. Sender: erics@cadkey.com
  7. Organization: cadkey
  8. References: <1992Dec15.183649.20994@delfin.com> <BzBzL2.5rx@apollo.hp.com>
  9. Date: Thu, 17 Dec 1992 18:48:41 GMT
  10. Lines: 49
  11.  
  12. In article <BzBzL2.5rx@apollo.hp.com> vinoski@ch.apollo.hp.com (Stephen Vinoski) writes:
  13.   [ interesting problem deleted ]
  14. >
  15. >Your assignment operator first frees any memory pointed at by the
  16. >Thing::str data member, then copies directly into that freed memory.
  17. >For self-assignment, it is also copying from that same freed memory.
  18. >
  19. >To fix all of these problems, you should reimplement the assignment
  20. >operator as follows:
  21. >
  22. >    Thing &
  23. >    Thing::operator=(
  24. >        const Thing &rhs    // note the addition of const here
  25. >    )
  26. >    {
  27. >        if (this != &rhs) {
  28. >        if (str != 0) {
  29. >            free(str);
  30. >        }
  31. >        s = strdup(rhs.str);
  32. >        }
  33. >        return *this;
  34. >    }
  35. >
  36. >-steve
  37. >
  38. >Steve Vinoski  (508)436-5904   vinoski@apollo.hp.com
  39. >Distributed Object Computing Program
  40. >Hewlett-Packard, Chelmsford, MA 01824       These are my opinions.
  41.  
  42. Isn't there a problem with this code, since it checks to see if this
  43. is the same as the right hand side by pointer comparison?  Aren't
  44. pointer comparisons only defined if they point within the same object
  45. or array of objects?
  46.  
  47. My reading of the ARM (section 5.9) says that this comparison is
  48. undefined (or rather implementation dependent).  ANSI C (actually, I'm
  49. looking in the ISO document, I'm not sure if the section numbers are
  50. the same) has similiar language in 6.3.8 and 6.3.9.
  51.  
  52. I bring this up because I have a similar need for this comparison.  I
  53. need to know if this is the same as one of my arguments.  In light of
  54. the recent "total pointer ordering" discussions, I think there might
  55. be a problem here.
  56.  
  57. Any ideas?
  58.  
  59. Eric.
  60.  
  61.