I have a 100 byte long packet that is to be transmitted. I want to use it both as a linear array and I want to reference individual bits and bytes that have special meaning. Something like this...
/* 32bit machine */ typedef union PACKET_U { struct LABEL_S { unsigned char dst_addr;
unsigned char src_addr;
unsigned char data1 : 1; unsigned char dummy : 4; signed char data2 : 3;
unsigned char data3 : 4; signed char data4 : 4;
unsigned int data5;
unsigned char data6[95]; } label;
unsigned char linear_array[100]; } packet;
Can I mix bitfields and other types in the same scope (LABEL_S) ?
Is there a better way of doing this?
I am aware of the issues with read-modify-write, and atomic operations, etc.
Thanks.