From 7272821276496170801
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8372ae6de42be399
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2004-02-23 20:50:05 PST
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!news-out.visi.com!green.octanews.net!news-out.octanews.net!news.glorb.com!news-spur1.glorb.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ucar.edu
From: "Andrew Koenig" <ark@acm.org>
Newsgroups: comp.std.c++
References: <403601F6.8010706@ircad.u-strasbg.fr> <c15mlg$pdl$1@news1nwk.SFbay.Sun.COM> <m3y8qwp6uy.fsf@merlin.cs.tamu.edu>
Subject: Re: Array of size 0
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <Egr_b.78425$hR.1612895@bgtnsc05-news.ops.worldnet.att.net>
X-Complaints-To: abuse@worldnet.att.net
X-Trace: bgtnsc05-news.ops.worldnet.att.net 1077559460 408b0b78ebacdc31aea9d1c5ccf1b423 (Mon, 23 Feb 2004 18:04:20 GMT)
NNTP-Posting-Date: Mon, 23 Feb 2004 18:04:20 GMT
Organization: AT&T Worldnet
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=0.7 required=5.2 tests=AWL,PRIORITY_NO_NAME 
	autolearn=no version=2.60-mulga_r1
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Date: Mon, 23 Feb 2004 22:47:33 CST
Lines: 35
Xref: archiver1.google.com comp.std.c++:1216


"Gabriel Dos Reis" <gdr@cs.tamu.edu> wrote in message
news:m3y8qwp6uy.fsf@merlin.cs.tamu.edu...
> stephen.clamage@sun.com (Steve Clamage) writes:

> | Now consider
> | int* myArray = new int[n];
> | If n were not allowed to be zero, the runtime system would have to
> | check for zero elements and generate some kind of runtime error,
> | probably an exception. The program would have to check specially for
> | zero size or be prepared to deal with the exception -- perhaps in many
> | places.

> Is that really different from the current behaviour whereby the
> new-expression can throw because of shortage of storage and the
> program has to check?

Yes it is, because if running out of storage reliably yields an exception,
it is legitimate for programs to deal with those exceptions by ignoring
them.  In that case, either the program runs out of memory and terminates
due to an unhandled exception, or it doesn't run out of memory, and
completes normally.

If new is permitted to return zero, then every call to new must have a
corresponding test (although it might be possible to combine multiple tests
into one).  Otherwise, when memory is exhausted, the program is likely to
try to use a zero pointer as if it pointed to an object, resulting in
undefined behavior.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



