This code is for the Microchip PIC32MX microprocessor. Their compiler is essentially GCC 3.4.
I try to use the GCC __packed__attribute to pack the bit fields into a union, and then restore them as unsigned char(i.e. type-punning) for sending via SPI or I2C. This behavior is determined by my implementation and works great. I prefer this over a hundred lines of masking and offset :)
My question is: are there any attributes __packed__in the code below that are redundant? At first glance, I think that those of the union members at the highest level can be dispensed with, but I'm not sure. Or can I leave them in a nested structure?
typedef struct
{
unsigned FlagOne : 1 __attribute__((packed));
unsigned FlagTwo : 1 __attribute__((packed));
unsigned SomeData : 5 __attribute__((packed));
} BlobForSomeChip;
typedef union
{
BlobForSomeChip blobdata __attribute__((packed));
unsigned char bytes[4] __attribute__((packed));
} BlobData;