Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Structure initialization problem

Reply
Thread Tools

Structure initialization problem

 
 
Roy Smith
Guest
Posts: n/a
 
      09-04-2005
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?
 
Reply With Quote
 
 
 
 
Robert Gamble
Guest
Posts: n/a
 
      09-04-2005

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

 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      09-04-2005
In article <(E-Mail Removed) .com>,
"Robert Gamble" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what's the difference between value-initialization and default-initialization? Jess C++ 23 05-04-2007 03:03 AM
array initialization in initialization list. toton C++ 5 09-28-2006 05:13 PM
Initialization of non-integral type in initialization list anongroupaccount@googlemail.com C++ 6 12-11-2005 09:51 PM
Initialization via ctor vs. initialization via assignment Matthias Kaeppler C++ 2 07-18-2005 04:25 PM
Default Initialization Vs. Value Initialization JKop C++ 10 09-22-2004 07:26 PM



Advertisments