static const double pi = 3.1415;

Nathan Sidwell nathan@codesourcery.com
Wed Feb 19 17:12:00 GMT 2003


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@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org




More information about the Gcc mailing list