Article View: comp.std.c++
Article #3528Semantics of "new foo[0]"
From: G. Mike Butler D054
Date: Tue, 27 Feb 1996 23:13
Date: Tue, 27 Feb 1996 23:13
35 lines
1720 bytes
1720 bytes
According to the ARM section 5.3.3:
"operator new() can be called with the argument
zero. Repeated such calls return pointers to
distinct objects."
But when I execute the following:
#include <isotream.h>
main()
{
struct foo { char a[1024]; };
foo *p = new foo[0];
foo *q = new foo[0];
cout << (void *)p << " " << (void *)q << endl;
}
I get
0x338d8 0x338e8
While these are distinct pointers, the pointers refer to overlapping
objects. Is this a legitimate interpretation of section 5.3.3 or is
this a compiler/library bug?
Incidentally, the standard template library included with gcc 2.7.2
relies on "operator new(0)" working.
Thanks,
-Mike Butler
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<MGB.96Feb27175316@kronecker.mitre.org>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: mgb@kronecker.mitre.org (G. Mike Butler D054) Newsgroups: comp.std.c++ Subject: Semantics of "new foo[0]" Date: 27 Feb 1996 15:13:07 PST Organization: The MITRE Corporation Approved: austern@isolde.mti.sgi.com Message-ID: <MGB.96Feb27175316@kronecker.mitre.org> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 27 Feb 1996 22:53:16 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMTOQFUy4NqrwXLNJAQHyAQH/Uqi0qICJ0/QkIcQKIPns4ov7R83Hw+XV eO/pcLOASDnwmB1VJmYtk17A0kOPKm2bJP0SK0zwhmTHfWST2KDbSg== =a22R Originator: austern@isolde.mti.sgi.com