Topic
No replies
SystemAdmin
SystemAdmin
196 Posts
ACCEPTED ANSWER

Pinned topic 64 bit integer long long type for bit fields

‏2012-05-23T13:33:35Z |
Hi,

we have need to store integers larger than 32 bits within a structure and to conserve space we want to use a bit field of less than 64 bits within a 64-bit containing structure field. For other platforms we use a type of long long to ensure we are getting a 64-bit integer field. For example:

typedef struct {

unsigned long long junk :8;
unsigned long long junk2 :8;
unsigned long long page :48;

} struct2;

and this worked fine on linux and Solaris and the documentation for AIX's XL C/C++ compiler indicates bit field containers can have types of long long, but on XL C the compiler complains and we don't get the desired result - it doesn't point to the bit field length as the problem, but the "long long" type. We find that we can use just unsigned long and still get a 64-bit field on 64-bit AIX, but this specification doesn't work on 32-bit platforms. We are trying to use "long long" to be more widely compatible across platforms. Since the compiler documentation says bit field types of "long long" are allowed, why is this failing with the messages:

1506-159: (E) Bit field type specified for junk is not valid. Type unsigned assumed.
1506-159: (E) Bit field type specified for junk2 is not valid. Type unsigned assumed.
1506-159: (E) Bit field type specified for page is not valid. Type unsigned assumed.
1506-003: (E) Width of a bit field of type "unsigned int" cannot exceed 32.

and results in a 32-bit container field. Temporarily we are using a type of "unsigned long" on AIX to get around this.