static const double pi = 3.1415;
Nathan Sidwell
nathan@codesourcery.com
Thu Feb 20 12:04:00 GMT 2003
Mike Stump wrote:
> I still feel like I am on Mars:
I suspect we have not defined the 'argument' (A sequence of statements ....
that's not an argument, you're merely contradicting me ...)
> Oh, and by the way if you are correct, that it can be something other
> than a constant, why does the compiler give:
>
> bash-2.05a$ gcc -O3 -S t.c
> t.c:3: initializer element is not constant
>
> in the case of C.
>
> double bar();
>
> static const double d = bar();
1) C and C++ are different in this respect
2) C89 and C99 *might* be different, I only have a C99 spec available.
3) C99 says the initializer must be a constant expression, *but not
necessarily a constant integral expression* C99[6.7.8]/4. A constant
expression shall not contain ... function call C99[6.6]/3. An integral
constant expression 'shall only have the following ... float constants
that are the immediate operands of casts' C99[6.6]/6
4) C++ allows an initializer of a non-member static object to be 'an arbitrary
expression' C++[8.5]/2
Now, it seems from (3) that the compiler must be able to perform
float folding, the whole rationale of (3) appears to restrict initializers
to those things that could be evaluated at compile time. The C++ std
says that integral constant expressions 'shall only contain ...
const variables or static data members of integral or enumeration type
initialized with constant expressions'C++[5.19]/1. So there already
is the restriction that some constant things are not suitable for
a constant expression. Later on there is the further restriction
(the point of your contention, I beleive), that constant static data
members shall only be initialized in class by constant integral
expressions.
That does look superfluous (the restriction on what a static const data member
may be initialized with), and I think there is a strong case
for making it a g++ extension, given the prior art we already have.
Care to file a Defect Report? (Maybe there already is one)
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