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


> Date: Fri, 16 Jul 1999 09:48:29 +0400 (MEDT)
> From: Andrey Slepuhin <pooh@msu.ru>

> Oops, it indeed return the same value, so pointer increment is done
> via egcs itself. Sorry. Interesting enough, what part of standard
> allows such behavior.

No.  What part of the standard says it does?  Anyway, like I said,
comp.lang.c++ is a better place to learn about C++.  Not this list.
But, since you already quoted it:

5.3.4 New:

  -      new(2,f) T[5]     results     in      a      call      of
    operator new[](sizeof(T)*5+y,2,f).

> So having

>   X* p1=new(p) X[N];
>   X* p1=(X*)(operator new(N,p));

> in the first case p1=p+4, and in the second case p1=p. Is it right?

Yes.

> And something similar is with non-placement new. So 

>   X* p=new X[N];
>   operator delete[] (p);

> simply dumps a core on my machine.

If you want to write the above, you haven't yet mastered C++.  Go read
a book on it.  If you can find the above in a book, please quote it
here, as that is a book we all should avoid.

If you think it does something interesting, please cite the Standard
that defines the semantics of it.

> > Yes, and this is via 5.3.4, as discussed in 5.3.4.

> Yes, of course.

Then why ask above?

> >> So passed value differs from returned.
> > 
> > No, you have not shown that.
> > 
> >> This is separate topic. And there will be implementation problems,
> >> though this is possible.
> > 
> > I don't know of any, would you care to elaborate?

> But what is your point here? There are the following abilities:

> 2) However we still can call placement delete[] by
> typing operator delete (p,p).

This isn't valid.  So we can ignore it.

> If we really can do this (see above).

Nope, we invalid.


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