Pelles C forum

Pelles C => General discussions => Topic started by: post from old forum on September 13, 2004, 09:12:57 PM

Title: sizeof
Post by: post from old forum on September 13, 2004, 09:12:57 PM
I have this struct:
struct client_data
{
unsigned long ip_no;
unsigned short port_no;
long size;
short reserved;
};

two shorts ( = 4 bytes) and two longs ( = 8 bytes). But its size is 16 bytes. Does anybody know why?

bera
Title: sizeof
Post by: post from old forum on September 13, 2004, 09:13:24 PM
For performance reasons, data needs to be aligned to certain boundaries . Usually 4bytes (32 bits). C compilers will automatically align members of structures on 4byte boundaries unless specifically told not to.

Whatever
Title: sizeof
Post by: post from old forum on September 13, 2004, 09:13:50 PM
Look at #pragma pack ... in the help file, if you want to change the default behaviour.

Pelle