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

Didier Kryn kryn@in2p3.fr
Fri May 8 14:14:00 GMT 2015


     Your expression just doesn't make any sense in C; therefore it 
would be very bad for whatever C compiler to give it one.

     Please, I don't want to know what it could mean in C++. Maybe you 
are a victim of the old statement that "C++ = C plus the class". But the 
two languages have started to diverge from the beginning, maybe two 
decades ago.

     You are not going to write working C programs by assuming that "C = 
C++ minus the class". You should better start from scratch with a C 


Le 08/05/2015 15:34, m-h-l a écrit :
> I guess you refer to this part of the standard:
> "The array-subscript [] and member-access . and -> operators, the address &
> and indirection * unary operators, and pointer casts may be used in the
> creation of an address constant, but the value of an object shall not be
> accessed by use of these operators."
> Funny thing is that g++, ArmC and ICC do not have a problem with "abcdef"[3]
> as an initializer.
> So I wonder what shall be the sense to forbid this in gcc.
> This way I cannot use gcc to calculate e.g. CRCs or Hashs over real constant
> things at build time without extra tools, even not in such a clear case as
> here. With the other compilers its no problem.
> What a pity!
> --
> View this message in context: http://gcc.1065356.n5.nabble.com/gcc-why-is-abcdef-3-not-a-constant-error-initializer-element-is-not-constant-tp1146945p1147037.html
> Sent from the gcc - Help mailing list archive at Nabble.com.

More information about the Gcc-help mailing list