union issue
Mihai Donțu
mihai.dontu@gmail.com
Tue May 29 13:34:00 GMT 2007
Hi,
I have a "tiny" problem with gcc (or a certain standard
that did not show in my grep results). Given the sample code
below:
#include <stdio.h>
#include <stdint.h>
#define __PACKED __attribute__((packed))
typedef struct _type1_t {
uint32_t field1:31;
uint32_t field2:1;
} __PACKED type1_t;
typedef struct _type2_t {
union {
uint32_t field1:31;
uint32_t field2:15;
};
uint32_t field3:1;
} __PACKED type2_t;
int main( void )
{
type1_t a;
type2_t b;
printf( "%d %d\n", ( int )sizeof( a ), ( int )sizeof( b ) );
return 0;
}
which (as some of you might have already guessed) gives me:
mihai@mdontu-l:~$ gcc test.c
mihai@mdontu-l:~$ ./a.out
4 5
is there any way to instruct gcc not to pack the union into a dword?
I *think* on PPC -mbit-align does the trick (I have no PPC around to
run a test).
Thanks in advance,
--
Mihai DonÈu
More information about the Gcc-help
mailing list