C bit structure

Alec Shaw shaw.alec at gmail.com
Thu Mar 19 18:33:48 MDT 2009


I want to implement a struct that is 4 bytes in size that has alternate 
bit fields
similar to the following.  The struct below is 12 bytes in size.
Any suggestions on how create a similar structure of only 4 bytes.
I want to overlay the structure on a character stream.

typedef struct {
    unsigned int a:8;
    union {
        struct {
            unsigned int 1ba:4;
            unsigned int 1bb:4;
        } type1b;
        struct {
            unsigned int 2ba:8;
        } type2b;
        struct {
            unsigned int 3ba:1;
            unsigned int 3bb:1;
            unsigned int 3bc:1;
            unsigned int 3bd:2;
            unsigned int 3be:3;
        } type3b;
    } u;
    unsigned int c:16;
} mystruct;

Thanks
Alec Shaw




More information about the PLUG mailing list