From 1454777776533923675
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,add62e0f5e586127
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-09-26 03:49:49 PST
Newsgroups: comp.std.c++
Path: bga.com!news.sprintlink.net!howland.reston.ans.net!EU.net!uknet!festival!dcs.ed.ac.uk!cnews
From: ddr@dcs.ed.ac.uk (Douglas Rogers)
Subject: Re: compile time consts
In-Reply-To: rfg@netcom.com's message of Sat, 24 Sep 1994 07:54:40 GMT
Message-ID: <DDR.94Sep26105635@drongs.dcs.ed.ac.uk>
Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
Organization: Department of Computer Science, Edinburgh University
References: <1994Sep19.110228.3591@fmrco.uucp> <weissmanCwHpDL.LD5@netcom.com>
	<rfgCwMJB4.E1s@netcom.com>
Date: Mon, 26 Sep 1994 09:56:31 GMT
Lines: 61

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


rfg> In article <weissmanCwHpDL.LD5@netcom.com> weissman@netcom.com
rfg> (Bob Weissman) writes:

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

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

Unfortunately I don't have a copy of the draft standard, and I can
find no mention of the problem or suitable exasmples in the ARM but the
implication is that the compiler may need some compile time capability
to evaluate expressions.  The idea of const in C++ is to enable a
const value to be used within a static decleration.

in C this is illegal but in C++ encouraged:-

  const int MAX_STRING = 61;
  char string[MAX_STRING];

Now this form is not in dispute, in C this is not a problem as #define
is used ie:-

   #define MAX_STRING  61

   char string[MAX_STRING];

No worries, but now if we use an expression, in C the rules are clear,
the preprocessor must have certain mathematical capability ie:-

    #define STRING_LEN 60
    #define MAX_STRING STRING_LEN + 1;

    char string[MAX_STRING];


If we do the same in C++ then we need to know - what expressions can
be evaluated at compile time. Can this be?

     const int STRING_LEN = 60;
     const int MAX_STRING = STRING_LEN + 1;

Does this only apply to built in types? What about expressions in the
standard library as in the example above?





-- 
Douglas

---
=============================================================================
Douglas Rogers  MAIL: ddr@dcs.ed.ac.uk  Tel: +44 31-650 5172 (direct dial)
                                        Fax: +44 31-667 7209
============================= Mostly harmless ===============================


