From: Joaquín Cuenca Abela (cuenca@pacaterie.u-psud.fr)
Date: Sun Jun 02 2002 - 10:33:53 EDT
On Thu, 2002-05-30 at 20:23, Tomas Frydrych wrote:
>
> > In short, the whole reason we created those macros was to ensure that
> > all delete, free, etc. calls did all of the nice null-sanity work
> > you'd usually want. Thus instead of typing the risky:
> >
> > delete m_pHeaderSL;
> >
>
> Correct me if I am mistaken, but the c++ operator is designed to
> handle NULLs, so it is not really necessary to this kind of a check;
> its a different story with free though, isn't it?
afaik free should also handle NULLs, but it was not the case in older
versions of ANSI C, so I guess that there are still out there some
compilers that don't handle the free(NULL); case
Btw, if we want to keep DELETEP, we can make it a bit more useful than
now (the only useful bit right now if the ptr = NULL; part). We can do
something as:
#define DELETEP(ptr) \
do {} while(sizeof(*ptr) == 0); \
delete ptr; \
ptr = NULL;
to prevent trying to delete a type not yet known to the compiler,
because the standard doesn't forces a compiler to issue a warning in
this case, and the result is undefined (the compiler can not known if
the type has a trivial destructor).
I usually use a template to do that (from boost), but here templates are
a no-no.
Cheers,
-- Joaquín Cuenca Abela cuenca@pacaterie.u-psud.fr
This archive was generated by hypermail 2.1.4 : Mon Jun 03 2002 - 05:19:45 EDT