From 5779229166741391559
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8372ae6de42be399
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2004-02-20 14:25:17 PST
Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: do-not-spam-benh@bwsint.com (Ben Hutchings)
Newsgroups: comp.std.c++
Subject: Re: Array of size 0
Date: Fri, 20 Feb 2004 22:25:16 +0000 (UTC)
Lines: 34
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <slrnc3cmjj.p3b.do-not-spam-benh@shadbolt.i.decadentplace.org.uk>
References: <403601F6.8010706@ircad.u-strasbg.fr>
X-Trace: mail2news.demon.co.uk 1077315916 28000 10.0.0.1 (20 Feb 2004 22:25:16 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 20 Feb 2004 22:25:16 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1AuJ59-0007HT-00
	for mail2news@news.news.demon.net; Fri, 20 Feb 2004 22:25:15 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i1KMPCi2016950; Sat, 21 Feb 2004 09:25:12 +1100 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i1KMPBXP016941;
	Sat, 21 Feb 2004 09:25:11 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-Reply-To: Ben Hutchings <benh@bwsint.com>
X-Orig-NNTP-Posting-Host: cpc1-cmbg1-4-0-cust94.cmbg.cable.ntl.com (62.253.133.94)
X-Orig-X-Trace: news.uni-berlin.de 1077304505 47792262 I 62.253.133.94 ([70929])
X-Orig-Path: decadentplace.org.uk!nobody
X-User-Agent: slrn/0.9.7.4 (Linux)
X-Spam-Level: 
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.0 required=5.2 tests=none autolearn=no 
	version=2.60-mulga_r1
Xref: archiver1.google.com comp.std.c++:1187

Julien Lamy wrote:
> Hello,
> According to paragraph 6 of item 5.3.4 in the Standard, it is legal to
> dynamically allocate an array of size 0, i.e.
> new int[0]
> is legal.
> However, as I understand paragraph 1 of item 8.3.4 ("if the cosntant
> expression is present, [...] its value shall be greater than zero"), it
> is not legal to have
> int myArray[0]
> What is the rationale behind this difference ?

I don't know what reasons the committee had, and sadly they were
not systematically recorded, but I can certainly see a justification.

If the program does not decide until run-time just how many elements
will be in an array (as in the case of a new-expression) then it is
reasonable that it might sometimes decide that there will be none at
all, and the programmer shouldn't need to make that a special case. 
However, if the programmer must decide in advance how many elements
there will be (as in the case of a declaration) then clearly there
is no point in creating an array that will always be empty.

(Some implementations allow declaration of arrays of dimension 0 as an
extension, but the main reason for this is to support another
extension which allows an array at the end of a struct to be treated
as having a larger dimension than it is declared with.)

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



