Problem is solved. Mistake was not to rethink about given datatypes... The size of following structure is bigger than it should be:
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
struct Y
{
short h;
byte i;
}
#if defined (__GNUC__)
__attribute__((__packed__));
#endif
struct X
{
short a;
byte b;
byte c;
word d;
dword e;
byte f;
byte g;
word h;
short i;
struct Y G[8];
}
#if defined (__GNUC__)
__attribute__((__packed__));
#endif
printf("size of X should be 40 but is %i", sizeof(struct X));
Output:
size of X should be 40 but is 44
I need this structure with a size of 40 Bytes (sum of all elements), 44 is the lowest I can reach. Compiler is GCC C, byte
is unsigned char
, word
is unsigned short
and dword
is unsigned long
. sizeof(Y)
is 3. What is the problem here?