Re: OT: Language War (Re: "C" Manual)
Richard Cobbe wrote:
>
> Lo, on Thursday, January 3, William T Wilson did write:
>
> > On Wed, 2 Jan 2002, Richard Cobbe wrote:
> >
> > > I'll agree that the two are related; in fact, I'd go so far as to say
> > > that if a language supports dynamic memory allocation and type-safety,
> > > it *has* to have some sort of automatic storage management system.
> >
> > I don't think that necessarily follows; a manual mechanism for freeing
> > resources would then just set the reference to a NULL value.
>
> Not in the general case, no.
>
> std::string *s = new string("foo");
> std::string *s2 = s;
>
> delete s;
>
> If we assume a variant of C++ that extends delete to set its argument
> pointer to NULL, you still have the problem of s2 hanging around. In
> the general case, it's not so obvious that you've got two pointers to
> reset.
unless, of course, you also keep track of who points to given piece of
memory ;-) whoops...
erik
Reply to: