www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why does the rhs of delete have to be lvalue?

reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:

Mar 10 2005
next sibling parent reply xs0 <xs0 xs0.com> writes:
Just out of curiosity - when is it a problem?
Mar 11 2005
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
I'm formulating a treatise on why delete should be dropped for removing 
elements from AAs, and this is making it easier than I'd expected. ;)

"xs0" <xs0 xs0.com> wrote in message 
news:d0rrqh$1kk8$1 digitaldaemon.com...
 Just out of curiosity - when is it a problem? 
Mar 11 2005
prev sibling next sibling parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
Doesn't it have to be a reference or pointer to something allocated using 
'new' (aside from the AA usage)? I'm not exactly sure what is 'delete'able 
and what isn't. 
Mar 11 2005
prev sibling next sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Matthew wrote:
[nothing but the topic]

I believe because the value is being written to. E.g. when it is a
pointer it gets nulled out.

[though that's probably not what Matthew wants to hear from me. i
apparently don't get the vague hint but seeing this Matthew might want
to explain something to dumbasses such as myself]

[I should have probably considered posting the whole message in the
subject line though]

-eye
Mar 11 2005
prev sibling next sibling parent reply "Walter" <newshound digitalmars.com> writes:
So the reference can be nulled out. You won't have to write:

    delete p;
    p = null;

which is a common C++ idiom.
Mar 11 2005
next sibling parent Derek Parnell <derek psych.ward> writes:
On Fri, 11 Mar 2005 13:23:04 -0800, Walter wrote:

 So the reference can be nulled out. You won't have to write:
 
     delete p;
     p = null;
 
 which is a common C++ idiom.
So would it be possible to change the D behaviour such that if the coder used a lvalue, D would null it out, otherwise if the coder did not use an lvalue then D would not attempt to null it out. Also, this is the sort of thing that needs to be explicitly documented in the official docs. -- Derek Parnell Melbourne, Australia 12/03/2005 8:55:04 AM
Mar 11 2005
prev sibling parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Walter" <newshound digitalmars.com> wrote in message 
news:d0t3hr$h0a$1 digitaldaemon.com...
 So the reference can be nulled out. You won't have to write:

    delete p;
    p = null;

 which is a common C++ idiom.
Gotcha. (That just adds grist to my mill, however, ....) :-)
Mar 11 2005
prev sibling parent David L. Davis <SpottedTiger yahoo.com> writes:
In article <d0qrve$gm9$1 digitaldaemon.com>, Matthew says...

Matthew this may seem like a pretty dumb question, but what does RHS stand for?
I'm thinking that it stands for "Right Hand Side."  

Thanks in advance.

David L.

P.S. When I was in the U.S. Army we had a saying, that "The only dumb question,
is the one that wasn't asked."

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Mar 12 2005