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: Placement new[] weirdness


Andrey Slepuhin wrote:

> On 16-Jul-99 Branko Cibej wrote:
> > Andrey Slepuhin wrote:
> >
> >> 2) However we still can call placement delete[] by
> >> typing operator delete (p,p). ...
> >
> > I think you're confusing destruction and deallocation.
> > They're not interchangeable.
>
> Yes I know. But indeed, there is something weird with new[] and delete[]:
> when you are using operator+, you can write
> both a+b and operator+(a,b). They are identical.
>
> new[] and delete[] are differ. Why? If the compiler
> catch expressions like "delete[] p;", calls object destructors,

There's the catch. the _compiler_ calls object destructors ...

> and then calls *deallocation* function, why it cannot catch

... and the deallocation function is called `operator delete'.

> expressions like "operator delete[](p);" and do the same thing?

Ah, you're looking for consistence in C++? Optimist! ;-)

> Or may be I'm not garanteed that a+b and operator+(a,b)
> are identical?

Yes, that's guaranteed.


As I mentioned in a earlier post, the `new', `new[]',
`delete' and `delete[]' operators are magic in C++
-- as oposed to `operator new', etc. What's confusing is
that the names are so similar: `new' <-> `operator new',
but that doesn't change the fact that their semantics are
different. It's just something you have to live with.

    Brane

--
Branko Čibej                 <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
voice: (+386 61) 186 53 49   fax: (+386 61) 186 52 70



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