don't pack my union

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux