Pelles C > General discussions

sizeof

(1/1)

post from old forum:
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:
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:
Look at #pragma pack ... in the help file, if you want to change the default behaviour.

Pelle

Navigation

[0] Message Index

Go to full version