This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: malloc/free & new/delete balance


Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
> 
> Carlo Wood <carlo@runaway.xs4all.nl> writes:
> 
> > WEAK (void operator delete[] (void *ptr) throw ())
> > {
> >   if (ptr)
> >     free (ptr);
> > }
> 
> > This unbalance between calling `::operator new(size_t)' and `free(void *)'
> > is causing troubles when `operator new(size_t)' and `operator delete(void *)'
> > are overloaded
> 
> Agreed, but, for some reason, the FDIS [lib.new.delete.array] defines
> operator new[](size_t) as returning operator new(size_t) by default,
> while it states that operator delete[](void*) frees the pointer it is
> given.  

Huh?  It's correct in the Nov'96 paper.  "For such a non-null value of
ptr, reclaims storage allocated by the earlier call to the default
operator new[]."  Nothing about free in there.  You mean they changed it
to something obviously incorrect?  *None* of the deletes should be defined
in terms of free...  (Implemented, sure, but not defined.)

> So, I'd say the implementation is correct, and calling operator
> delete(void*) is non-standard.  Too bad. :-(

While it isn't that hard to get around (just replace the all operators 
with your own) it seems a shame to allow an obvious mistake like this into
EGCS.


-- 
Sol Foster: colomon@ralf.org

A genius is someone who travels to truth by an unexpected path.
Unfortunately, unexpected paths lead to disaster in everyday life.  
                                        -Alfred Bester


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]