Re: _strdup and delete
On Dec 17, 6:23 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
Andrey Tarasevich wrote:
If the memory is allocated with 'malloc/calloc', then you
simply cannot deallocate if with 'delete', period. There's
not much sense in discussing the "dangers" of trying to do
so.
I'm not aware of any guarantee that deleting malloc'd memory
will not free the memory. In fact, this is exactly what
happens on some platforms. "Simply cannot" is overstating the
case.
It's undefined behavior. In theory, an implementation could
define it, but they'd have to do so in a way that would work
with any user supplied global operator new/operator delete as
well. In practice, it's quite likely to cause problems as soon
as you replace the global new/delete operators (say with
debugging versions).
So "simply cannot" applies, just as it applies for using an
uninitialized variable, dereferencing a null pointer, using an
object after it has been freed, etc.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34