union issue
Andrew Haley
aph-gcc@littlepinkcloud.COM
Wed May 30 11:06:00 GMT 2007
Mihai Don?u writes:
> 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've read this three times now and I still don't understand your
question. You declare a packed struct, but you don't want it to be
packed? So don't declare it packed, then. But that can't be what you
really meant.
Andrew.
More information about the Gcc-help
mailing list