On 2012-10-08 23:24:42 +0000, James Cameron said: > 48 bytes is wrong. 32 bytes is right. Your compiler might be > aligning the structure members for performance. Give a suitable > alignment directive to your compiler. We use __attribute__((packed)) > in the server code. Check the offset to each member using whatever > language facilities are available. In C we can use sizeof() and > offsetof(). So here's the debug using Jame's excellent advise. typedef struct _youServerPacket { char type; /* SP_YOU */ char pnum; /* Guy needs to know this... */ char hostile; char swar; char armies; char tractor; char pad2; char pad3; unsigned flags; long damage; long shield; long fuel; unsigned short etemp; unsigned short wtemp; unsigned short whydead; unsigned short whodead; } __attribute__ ((packed)) youServerPacketStruct; size = sizeof(youServerPacketStruct); NSLog(@"ServerPacketYou size=%d", size); NSLog(@"type %lu:%ld\n", offsetof(youServerPacketStruct, type), sizeof(char)); NSLog(@"pnum %lu:%ld\n", offsetof(youServerPacketStruct, pnum), sizeof(char)); NSLog(@"hostile %lu:%ld\n", offsetof(youServerPacketStruct, hostile), sizeof(char)); NSLog(@"swar %lu:%ld\n", offsetof(youServerPacketStruct, swar), sizeof(char)); NSLog(@"armies %lu:%ld\n", offsetof(youServerPacketStruct, armies), sizeof(char)); NSLog(@"tractor %lu:%ld\n", offsetof(youServerPacketStruct, tractor), sizeof(char)); NSLog(@"pad2 %lu:%ld\n", offsetof(youServerPacketStruct, pad2), sizeof(char)); NSLog(@"pad3 %lu:%ld\n", offsetof(youServerPacketStruct, pad3), sizeof(char)); NSLog(@"flags %lu:%ld\n", offsetof(youServerPacketStruct, flags), sizeof(unsigned)); NSLog(@"damge %lu:%ld\n", offsetof(youServerPacketStruct, damage), sizeof(long)); NSLog(@"shield %lu:%ld\n", offsetof(youServerPacketStruct, shield), sizeof(long)); NSLog(@"fuel %lu:%ld\n", offsetof(youServerPacketStruct, fuel), sizeof(long)); NSLog(@"etemp %lu:%ld\n", offsetof(youServerPacketStruct, etemp) , sizeof(unsigned short)); NSLog(@"wtemp %lu:%ld\n", offsetof(youServerPacketStruct, wtemp), sizeof(unsigned short)); NSLog(@"whydead %lu:%ld\n", offsetof(youServerPacketStruct, whydead), sizeof(unsigned short)); NSLog(@"whodead %lu:%ld\n", offsetof(youServerPacketStruct, whodead), sizeof(unsigned short)); 2012-10-08 22:48:06.564 Packet[10189:303] ServerPacketYou size=44 2012-10-08 22:45:42.254 Packet[10152:303] type 0:1 2012-10-08 22:45:42.255 Packet[10152:303] pnum 1:1 2012-10-08 22:45:42.255 Packet[10152:303] hostile 2:1 2012-10-08 22:45:42.255 Packet[10152:303] swar 3:1 2012-10-08 22:45:42.256 Packet[10152:303] armies 4:1 2012-10-08 22:45:42.256 Packet[10152:303] tractor 5:1 2012-10-08 22:45:42.256 Packet[10152:303] pad2 6:1 2012-10-08 22:45:42.256 Packet[10152:303] pad3 7:1 2012-10-08 22:45:42.256 Packet[10152:303] flags 8:4 2012-10-08 22:45:42.257 Packet[10152:303] damge 12:8 2012-10-08 22:45:42.257 Packet[10152:303] shield 20:8 2012-10-08 22:45:42.257 Packet[10152:303] fuel 28:8 2012-10-08 22:45:42.257 Packet[10152:303] etemp 36:2 2012-10-08 22:45:42.257 Packet[10152:303] wtemp 38:2 2012-10-08 22:45:42.258 Packet[10152:303] whydead 40:2 2012-10-08 22:45:42.258 Packet[10152:303] whodead 42:2 NOTE that sizeof(long) = 8, so I wiped up this program. Compiling with -m32 I get sizeof(long) = 4 #include <stdio.h> main() { printf("char %ld\n", sizeof(char)); printf("unsigned %ld\n", sizeof(unsigned)); printf("long %ld\n", sizeof(long)); printf("unsigned short %ld\n", sizeof(unsigned short)); } $ gcc size.c ; ./a.out char 1 unsigned 4 long 8 unsigned short 2 $ gcc -m32 size.c ; ./a.out char 1 unsigned 4 long 4 unsigned short 2 Recommendations (sorry tired and lazy, so throwing it to the mailing list for answers)? Guess I can look up the -std=c99 stuff? -- Bob Tanner <basic at us.netrek.org> Key fingerprint = 9906 320A 8BB6 64AD 96A7 7785 CBFB 10BF 568B F98C -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mailman.us.netrek.org/pipermail/netrek-dev/attachments/20121008/c470ebd6/attachment.html>