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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

if I write this little code and compile with gcc-4.x.x then I get:
error: initializer element is not constant

#include <stdio.h>
#include <string.h>

typedef struct
{
    char  oneChar;
    void *ptr2;
} xxx_t;

int main( void )
{
    static xxx_t ms =  { "12345"[3], 0 };

    printf("\n\n MyOutput: 0x%x  0x%x \n\n", ms.oneChar, ms.ptr2 );
}

(I know that this code is rubbish but this just an extract from a bigger
issue, broken down to this)

What can be more constant than  "12345"[3] ?

In g++ it works ... but I have to use gcc.

Any help about how to get this solved is welcome :-)




--
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-tp1146945.html
Sent from the gcc - Help mailing list archive at Nabble.com.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux