🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3576

Re: Semantics of "new foo[0]"

#3576
From: Steve Nutt
Date: Mon, 04 Mar 1996 18:25
50 lines
2434 bytes
mgb@kronecker.mitre.org (G. Mike Butler D054) wrote:

>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 
>]

Why do you say these are overlapping objects? You have not allocated
any objects of type foo. I would say the operator new foo[0] is
working as expected for you.

Steve
---
[ 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: <4hb8hu$afq@post.acadia.net>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <MGB.96Feb27175316@kronecker.mitre.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: steven2@salesbook.com (Steve Nutt)
Newsgroups: comp.std.c++
Subject: Re: Semantics of "new foo[0]"
Date: 04 Mar 1996 10:25:47 PST
Organization: DET
Approved: austern@isolde.mti.sgi.com
Message-ID: <4hb8hu$afq@post.acadia.net>
References: <MGB.96Feb27175316@kronecker.mitre.org>
Reply-To: steven2@salesbook.com
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Sun, 03 Mar 1996 07:20:42 GMT
X-Newsreader: Forte Free Agent 1.0.82
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMTs1v0y4NqrwXLNJAQE22gIApVMIFnpE1oZfSQeEqCPh+YJJfj9BUK3x
 Fpr1IL2xsSCZcOGhcrnT7CcMvSpG7batkc9Jis0ummQaIeHyY5SyHw==
 =BsjR
Originator: austern@isolde.mti.sgi.com