NO

Author Topic: sizeof  (Read 5318 times)

post from old forum

  • Guest
sizeof
« 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

post from old forum

  • Guest
sizeof
« Reply #1 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

post from old forum

  • Guest
sizeof
« Reply #2 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