Britton Leo Kerin <[EMAIL PROTECTED]> writes:

>   static char *const foo = "baz";
>   static int foo_len = strlen(foo);
>   /* static int foo_len = an_impure_function(); */

> greenwood$ gcc test_const.c
> test_const.c: In function `main':
> test_const.c:14: error: initializer element is not constant
> greenwood$ 
> 
> Replaceing the strlen call with a call of an impure function
> (commented out above) results in the above error whether or not -O is
> used.  It seems to me that pure function should either always be
> usable in this way regardless of -O (and C200? should endorse pure
> attribute and mandate the behavior), or never be supported.

This has nothing to do with pureness; the standard mandates a constant
expression as initializer, and when optimizing, gcc replaces
"strlen(foo)" with 3. Correct handling of constant expressions in gcc
is mostly unimplemented, see http://gcc.gnu.org/PR456.

I suggest we either mark this as forwarded pointing to above bug, or
close it, since it is IMHO a pretty minor issue...

-- 
        Falk


Reply via email to