This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: static const double pi = 3.1415;
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Mike Stump <mstump at apple dot com>
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>, Mark Mitchell<mark at codesourcery dot com>, Mike Stump <mrs at apple dot com>, "gcc at gcc dot gnu dot org"<gcc at gcc dot gnu dot org>
- Date: Wed, 19 Feb 2003 16:52:14 +0000
- Subject: Re: static const double pi = 3.1415;
- Organization: Codesourcery LLC
- References: <2E054BFC-4421-11D7-B22E-003065A77310@apple.com>
Mike Stump wrote:
Personally, I don't find
int i = 1;
to be substantially different from:
double i = 1;
:-( As far as extensions go, I've seen worse.
you also have to extend the meaning of a constant-expression. [9.4.2] says
that the initializer for a static int member must be a constant integral
expression. To allow float you'd have to define what a constant float
expression is, and that'd mean you'd have to define how to do float
arithmetic at compile time. Not that any of that is insurmountable,
but you need to define it.
Your example 'static double d = 1' doesn't look that different,
until you realise there's an implicit cast, and it is really
'static double d = static_cast <double> (1)'
Simply allowing a double static member, without allowing constant float
expressions would be confusing, as
static double d1 = 1 * 2; // ok
static double d2 = 1.0 * 2; // not ok, (huh?)
Hope that helps.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan at codesourcery dot com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm dot org