From 9097899573987642520
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,add62e0f5e586127
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-09-26 12:18:45 PST
Newsgroups: comp.std.c++
Path: bga.com!news.sprintlink.net!howland.reston.ans.net!xlink.net!slsv6bt!slsv6bt!kanze
From: kanze@us-es.sel.de (James Kanze US/ESC 60/3/164 #71425)
Subject: Re: compile time consts
In-Reply-To: rfg@netcom.com's message of Sat, 24 Sep 1994 07:54:40 GMT
Message-ID: <KANZE.94Sep26200945@slsvhdt.us-es.sel.de>
Sender: news@lts.sel.alcatel.de
Organization: SEL
References: <1994Sep19.110228.3591@fmrco.uucp> <weissmanCwHpDL.LD5@netcom.com>
	<rfgCwMJB4.E1s@netcom.com>
Date: 26 Sep 1994 19:09:45 GMT
Lines: 45

In article <rfgCwMJB4.E1s@netcom.com> rfg@netcom.com (Ronald
F. Guilmette) writes:

|> In article <weissmanCwHpDL.LD5@netcom.com> weissman@netcom.com (Bob Weissman) writes:
|> >In article <1994Sep19.110228.3591@fmrco.uucp>,
|> >David Binderman <dcb@lovat.fmrco.com> wrote:
|> >>I claim the following is legal code. Three compilers disagree with me. 
|> >>Who is correct ?

|> >The compilers are.

|> >>#include <math.h>

|> >>const int N = 1000;
|> >>const int Q = (int) sqrt( (double) N);
|> >>int a[ Q];

|> >See ARM 8.2.4, then see ARM 5.19.  The expression inside the brackets
|> >must be a constant-expression.

|> This part, I believe.

|> >Because "(int) sqrt((double) N)" is not a constant-expression, neither is "Q".

|> Can _anyone_ provide a chapter and verse citation to support this conclusion?
|> If so, I would greatly appreciate it.  Thanks.

In the ARM, section 5.19: "A constant-expression can involve only
literals, enumerators, const values of integral types initialized with
constant expressions, and sizeof expressions."

No mention of function calls, so the initialization expression of Q is
not a constant expression.  And since Q is not initialized with a
constant expression, an expression containing Q is not a constant
expression.

And of course, in section 8.2.4, the syntax for an array declaration
requires a constant-expression.
--
James Kanze      Tel.: (+33) 88 14 49 00     email: kanze@lts.sel.alcatel.de
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung




