This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: static const double pi = 3.1415;


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]