home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!psinntp!cadkey!erics
- From: erics@cadkey.com (Eric Smith)
- Subject: Re: What is this CFRONT 3.0 warning message trying to tell me?
- Message-ID: <1992Dec17.184841.4563@cadkey.com>
- Sender: erics@cadkey.com
- Organization: cadkey
- References: <1992Dec15.183649.20994@delfin.com> <BzBzL2.5rx@apollo.hp.com>
- Date: Thu, 17 Dec 1992 18:48:41 GMT
- Lines: 49
-
- In article <BzBzL2.5rx@apollo.hp.com> vinoski@ch.apollo.hp.com (Stephen Vinoski) writes:
- [ interesting problem deleted ]
- >
- >Your assignment operator first frees any memory pointed at by the
- >Thing::str data member, then copies directly into that freed memory.
- >For self-assignment, it is also copying from that same freed memory.
- >
- >To fix all of these problems, you should reimplement the assignment
- >operator as follows:
- >
- > Thing &
- > Thing::operator=(
- > const Thing &rhs // note the addition of const here
- > )
- > {
- > if (this != &rhs) {
- > if (str != 0) {
- > free(str);
- > }
- > s = strdup(rhs.str);
- > }
- > return *this;
- > }
- >
- >-steve
- >
- >Steve Vinoski (508)436-5904 vinoski@apollo.hp.com
- >Distributed Object Computing Program
- >Hewlett-Packard, Chelmsford, MA 01824 These are my opinions.
-
- Isn't there a problem with this code, since it checks to see if this
- is the same as the right hand side by pointer comparison? Aren't
- pointer comparisons only defined if they point within the same object
- or array of objects?
-
- My reading of the ARM (section 5.9) says that this comparison is
- undefined (or rather implementation dependent). ANSI C (actually, I'm
- looking in the ISO document, I'm not sure if the section numbers are
- the same) has similiar language in 6.3.8 and 6.3.9.
-
- I bring this up because I have a similar need for this comparison. I
- need to know if this is the same as one of my arguments. In light of
- the recent "total pointer ordering" discussions, I think there might
- be a problem here.
-
- Any ideas?
-
- Eric.
-
-