Structure initialization problem

R

Roy Smith

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?
 
R

Robert Gamble

Roy said:
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
 
R

Roy Smith

"Robert Gamble said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top