Hi guys,
Given the code below, I expect the both to be 4 bytes, but somehow the first one is 5 bytes. What do I missing here? Assuming there is a topic here somewhere I don't understand.
Compiler: gcc v5.1.0, mingw32
machine: x86-64bit
It does the same on an ARM as well.
Given the code below, I expect the both to be 4 bytes, but somehow the first one is 5 bytes. What do I missing here? Assuming there is a topic here somewhere I don't understand.
Compiler: gcc v5.1.0, mingw32
machine: x86-64bit
It does the same on an ARM as well.
C:
typedef struct TEST{
uint8_t data1;
uint16_t data2;
uint8_t data3;
}__attribute__((__packed__)) test_t;
typedef struct TEST2{
uint16_t data2; /* moved this to top */
uint8_t data1;
uint8_t data3;
}__attribute__((__packed__)) test2_t;
int main(int argc, char **argv){
/*! I expect them both to be 4 bytes
* Why the first one is 5 bytes??
*/
printf("size of test_t %zu\n", sizeof(test_t)); /* 5 bytes */
printf("size of test2_t %zu\n", sizeof(test2_t)); /* 4 bytes */
return 0;
}