Article View: comp.std.c++
Article #1625Re: Operator new Question
From: Ramesh Seshadri
Date: Sun, 06 Aug 1995 19:19
Date: Sun, 06 Aug 1995 19:19
50 lines
1569 bytes
1569 bytes
In <3vu2gv$kav@bmtlh10.bnr.ca> John Hickin <hickin@bnr.ca> writes:
>
>I accidently discovered that the following code compiles and executes
using my
>favourite compiler:
>
>#include <iostream.h>
>#include <stddef.h>
>
>void* operator new(unsigned sz,const char*,int)
>{
> return ::operator new(sz);
>}
>
>struct Foo { Foo(); ~Foo(); };
>
>Foo::Foo() { cerr << "Foo::Foo[this==" << (void*)this << ']' << endl;
}
>Foo::~Foo() { cerr << "Foo::~Foo[this==" << (void*)this << ']' <<
endl; }
>
>main()
>{
> Foo* p = new(__FILE__,__LINE__) Foo[ 42 ];
> delete[] p;
>}
>
>
>
>(1) Is it legal C++?
>(2) If so, what should the behavior be?
>
>In my environment (HP-UX 9.x, C++ A.03.05) the Foo::Foo's are called
but the
>Foo::~Foo's are not called. If i change new(__FILE__,__LINE__) to
just new the
>destructors get called as expected.
>
>--
>John Hickin Bell-Northern Research, Montreal, Quebec
>(514) 765-7924 hickin@bnr.ca
>
Yes it is a legal C++ code. And it is supposed to call the overloaded
new one time and the ctor and dtor of the Foo for 42 times. In my
environment (Microsoft Visual C++ 2.0) the same code is working without
any change.
- Ramesh S
rameshs@ix.netcom.com
Technical Details
Message-ID:
<4034j4$fqd@ixnews7.ix.netcom.com>Path:
arc1-ca.pugleaf.net!ix.netcom.com!netnewsReferences:
<3vu2gv$kav@bmtlh10.bnr.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!ix.netcom.com!netnews From: rameshs@ix.netcom.com (Ramesh Seshadri ) Newsgroups: comp.std.c++ Subject: Re: Operator new Question Date: 6 Aug 1995 19:19:00 GMT Organization: Netcom Message-ID: <4034j4$fqd@ixnews7.ix.netcom.com> References: <3vu2gv$kav@bmtlh10.bnr.ca> NNTP-Posting-Host: ix-pon-mi1-03.ix.netcom.com