gcc: why is "abcdef"[3] not a constant (error: initializer element is not constant)

Andrew Makhorin mao@gnu.org
Fri May 8 17:25:00 GMT 2015


On Fri, 2015-05-08 at 16:13 +0200, Toon Moene wrote:
> On 05/08/2015 03:34 PM, m-h-l wrote:
> 
> > Funny thing is that g++, ArmC and ICC do not have a problem with "abcdef"[3]
> > as an initializer.
> 
> Neither does Fortran:
> 
> toon@moene:~/src$ cat g.f
>        CHARACTER :: A = "12345"(3:3)
>        PRINT *,A
>        END
> 
> toon@moene:~/src$ gfortran g.f
> toon@moene:~/src$ ./a.out
>   3
> 
> 

This is not the same case, because in Fortran "12345" is a string
constant while in C it is an array of characters, not a constant.




More information about the Gcc-help mailing list