Structure initialization problem

Discussion in 'C Programming' started by Roy Smith, Sep 4, 2005.

  1. Roy Smith

    Roy Smith Guest

    I'm trying to build the BIND-8 name resolver library and am getting the
    following error:

    /opt/toolset/compiler/FD7/SUNWspro/bin/cc -mt -g
    -I/work/smithr/tickets/24256.sbc-leak/MAIN/users/smithr/resolver-te\
    st/bind/bind-9.3.1/lib/bind
    -I/work/smithr/tickets/24256.sbc-leak/MAIN/users/smithr/resolver-test/bind/b
    ind-9.3.1/lib/\
    bind/make/../port/solaris/include -I.. -I./../include -D_REENTRANT
    -c gai_strerror.c
    "gai_strerror.c", line 58: too many initializers for scalar
    cc: acomp failed for gai_strerror.c

    This is on a Solaris-8 box with the Sun compiler. The offending line of
    code is:

    static pthread_mutex_t lock = LIBBIND_MUTEX_INITIALIZER;

    which, when I run the compile with -E, gets expanded to:

    static pthread_mutex_t lock = { { { 0 , 0 , 0 , 0 , 0 } , { { { 0
    } } } , 0 } };

    pthread_mutex_t in turn is:

    typedef struct _pthread_mutex {
    struct {
    uint16_t __pthread_mutex_flag1;
    uint8_t __pthread_mutex_flag2;
    uint8_t __pthread_mutex_ceiling;
    uint16_t __pthread_mutex_type;
    uint16_t __pthread_mutex_magic;
    } __pthread_mutex_flags;
    union {
    struct {
    uint8_t __pthread_mutex_pad[8];
    } __pthread_mutex_lock64;
    struct {
    uint32_t __pthread_ownerpid;
    uint32_t __pthread_lockword;
    } __pthread_mutex_lock32;
    upad64_t __pthread_mutex_owner64;
    } __pthread_mutex_lock;
    upad64_t __pthread_mutex_data;
    } pthread_mutex_t;

    This looks perfectly reasonable to me. The first five 0's get assigned to
    ....flag1 through ...magic, the next 0 is __pthread_mutex_pad[0], and the
    last 0 is __pthread_mutex_data. Why the compiler error?
     
    Roy Smith, Sep 4, 2005
    #1
    1. Advertising

  2. Roy Smith wrote:
    > I'm trying to build the BIND-8 name resolver library and am getting the
    > following error:
    >
    > /opt/toolset/compiler/FD7/SUNWspro/bin/cc -mt -g
    > -I/work/smithr/tickets/24256.sbc-leak/MAIN/users/smithr/resolver-te\
    > st/bind/bind-9.3.1/lib/bind
    > -I/work/smithr/tickets/24256.sbc-leak/MAIN/users/smithr/resolver-test/bind/b
    > ind-9.3.1/lib/\
    > bind/make/../port/solaris/include -I.. -I./../include -D_REENTRANT
    > -c gai_strerror.c
    > "gai_strerror.c", line 58: too many initializers for scalar
    > cc: acomp failed for gai_strerror.c
    >
    > This is on a Solaris-8 box with the Sun compiler. The offending line of
    > code is:
    >
    > static pthread_mutex_t lock = LIBBIND_MUTEX_INITIALIZER;
    >
    > which, when I run the compile with -E, gets expanded to:
    >
    > static pthread_mutex_t lock = { { { 0 , 0 , 0 , 0 , 0 } , { { { 0
    > } } } , 0 } };


    It looks like you have an extra set of braces around your initializer,
    try this:

    static pthread_mutex_t lock = {{ 0, 0, 0, 0, 0 }, {{{0}}}, 0 };

    > pthread_mutex_t in turn is:
    >
    > typedef struct _pthread_mutex {
    > struct {
    > uint16_t __pthread_mutex_flag1;
    > uint8_t __pthread_mutex_flag2;
    > uint8_t __pthread_mutex_ceiling;
    > uint16_t __pthread_mutex_type;
    > uint16_t __pthread_mutex_magic;
    > } __pthread_mutex_flags;
    > union {
    > struct {
    > uint8_t __pthread_mutex_pad[8];
    > } __pthread_mutex_lock64;
    > struct {
    > uint32_t __pthread_ownerpid;
    > uint32_t __pthread_lockword;
    > } __pthread_mutex_lock32;
    > upad64_t __pthread_mutex_owner64;
    > } __pthread_mutex_lock;
    > upad64_t __pthread_mutex_data;
    > } pthread_mutex_t;
    >
    > This looks perfectly reasonable to me. The first five 0's get assigned to
    > ...flag1 through ...magic, the next 0 is __pthread_mutex_pad[0], and the
    > last 0 is __pthread_mutex_data. Why the compiler error?


    Robert Gamble
     
    Robert Gamble, Sep 4, 2005
    #2
    1. Advertising

  3. Roy Smith

    Roy Smith Guest

    In article <>,
    "Robert Gamble" <> wrote:

    > It looks like you have an extra set of braces around your initializer,
    > try this:
    >
    > static pthread_mutex_t lock = {{ 0, 0, 0, 0, 0 }, {{{0}}}, 0 };


    I just discovered:

    /* Shut up warnings about missing braces */
    #define SHUTUP_MUTEX_INITIALIZER 1
    #ifdef SHUTUP_MUTEX_INITIALIZER
    #define LIBBIND_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
    #else
    #define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
    #endif

    I'm not sure which compiler(s) were issuing the warnings, but obviously
    that's the problem. Commenting out the first #define solved the problem.
    Thanks for the help.
     
    Roy Smith, Sep 4, 2005
    #3
    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. JKop
    Replies:
    10
    Views:
    961
  2. Matthias Kaeppler
    Replies:
    2
    Views:
    457
    Victor Bazarov
    Jul 18, 2005
  3. Replies:
    6
    Views:
    472
    Ron Natalie
    Dec 11, 2005
  4. toton
    Replies:
    5
    Views:
    945
    Victor Bazarov
    Sep 28, 2006
  5. Jess
    Replies:
    23
    Views:
    953
Loading...

Share This Page