odd problem with static initializers

Discussion in 'C++' started by Ric Has, Oct 13, 2004.

  1. Ric Has

    Ric Has Guest

    I have the following code which won't compile:

    typedef myType1 {
    unsigned short v1,
    unsigned char v2,
    unsigned char v3
    }

    enum signals {
    SIG_A,
    SIG_B,
    SIG_C
    };

    static const myType myEvents[] = {
    {SIG_A, 0, 0},
    {SIG_B, 0, 0},
    {SIG_C, 0, 0}
    };

    The compiler error is
    error: a brace-enclosed initializer is not allowed here before '{' token

    This compiled fine with an old version of gcc, I think 2.96. This error
    came from a more recent
    vintage, 3.3.1.

    Can anyone tell me why this isn't compiling? Thanks.

    Ric
     
    Ric Has, Oct 13, 2004
    #1
    1. Advertising

  2. Ric Has wrote:
    >
    >
    > I have the following code which won't compile:
    >
    > typedef myType1 {
    > unsigned short v1,
    > unsigned char v2,
    > unsigned char v3
    > }




    What's this? Perhaps you meant

    struct myType1 {
    unsigned short v1;
    unsigned char v2;
    unsigned char v3;
    };


    or even this unusual:


    typedef struct myType1 {
    unsigned short v1;
    unsigned char v2;
    unsigned char v3;
    };





    >
    > enum signals {
    > SIG_A,
    > SIG_B,
    > SIG_C
    > };
    >
    > static const myType myEvents[] = {



    static const myType1 myEvents[] = {



    > {SIG_A, 0, 0},
    > {SIG_B, 0, 0},
    > {SIG_C, 0, 0}
    > };




    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Oct 13, 2004
    #2
    1. Advertising

  3. Correction:


    Ioannis Vranos wrote:

    > or even this unusual:



    typedef struct {
    unsigned short v1;
    unsigned char v2;
    unsigned char v3;
    }myType1;



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Oct 13, 2004
    #3
  4. Ric Has

    Ric Has Guest

    Yes, I meant struct, not typedef. I have the same error when I do typedef
    struct myType1...

    On Wed, 13 Oct 2004 04:09:53 +0300, Ioannis Vranos
    <> wrote:

    > Ric Has wrote:
    >> I have the following code which won't compile:
    >> typedef myType1 {
    >> unsigned short v1,
    >> unsigned char v2,
    >> unsigned char v3
    >> }

    >
    >
    >
    > What's this? Perhaps you meant
    >
    > struct myType1 {
    > unsigned short v1;
    > unsigned char v2;
    > unsigned char v3;
    > };
    >
    >
    > or even this unusual:
    >
    >
    > typedef struct myType1 {
    > unsigned short v1;
    > unsigned char v2;
    > unsigned char v3;
    > };
    >
    >
    >
    >
    >
    >> enum signals {
    >> SIG_A,
    >> SIG_B,
    >> SIG_C
    >> };
    >> static const myType myEvents[] = {

    >
    >
    > static const myType1 myEvents[] = {
    >
    >
    >
    >> {SIG_A, 0, 0},
    >> {SIG_B, 0, 0},
    >> {SIG_C, 0, 0}
    >> };

    >
    >
    >




    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Ric Has, Oct 13, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. j l
    Replies:
    5
    Views:
    408
    A. Bolmarcich
    Feb 23, 2004
  2. James Robert Leek

    JNI Invocation: static UN-initializers?

    James Robert Leek, Aug 31, 2004, in forum: Java
    Replies:
    2
    Views:
    514
    James Robert Leek
    Aug 31, 2004
  3. HK
    Replies:
    7
    Views:
    430
    Wibble
    May 30, 2005
  4. HK
    Replies:
    3
    Views:
    4,202
  5. Christopher Benson-Manica

    References to static fields in enum initializers

    Christopher Benson-Manica, Jul 5, 2007, in forum: Java
    Replies:
    1
    Views:
    348
    Christopher Benson-Manica
    Jul 5, 2007
Loading...

Share This Page