I've been searching a lot about this topic and I hope finally get the answer here.
I want to use a structure for specific hardware and I want to implement this in C; this is the packet I want:
typedef struct {
    quint8 startByte        :8;
    quint16 ch1             :11;
    quint16 ch2             :11;
    quint16 ch3             :11;
    quint16 ch4             :11;
    quint16 ch5             :11;
    quint16 ch6             :11;
    quint16 ch7             :11;
    quint16 ch8             :11;
    quint16 ch9             :11;
    quint16 ch10            :11;
    quint16 ch11            :11;
    quint16 ch12            :11;
    quint16 ch13            :11;
    quint16 ch14            :11;
    quint16 ch15            :11;
    quint16 ch16            :11;
    quint8 endByte1         :8;
    quint8 endByte          :8;
}packet;
If you calculate the size it is 25 bytes. but when I use sizeof(packet) I get 46.
Right now I'm using Qt 5.5 and I also want to use this code in Atmel studio 7 with AVR.
By the way I also have used #pragma pack(1) and also __attribute__((__packed__)) and got the sizeof(packet) equal to 35.
 
     
    