Comments: Authenticated sender is From: Paul To: djgpp AT sun DOT soe DOT clarkson DOT edu Date: Sat, 30 Sep 1995 12:25:23 +0000 Subject: Re: Actual sizes of structs under djgpp? Reply-To: digisoft AT eis DOT net DOT au > This is definitely a newby's question, and I apologize in advance if I > should have found the answer for myself. > Struct 1 is a bitfield, COORD, and takes 4 bytes; OK. > Struct 2 is two COORDS+ two UCHARS and takes 12 bytes not 10; Hmm, maybe > structs are long-aligned. > Struct 3 is char[13], 37 UCHAR, 2 shorts and takes 54 bytes; OK - but why? > 54 is not long-aligned. > I'm trying to transfer a lot of structures and their information from a > 68000 machine to a PC and it would help if there was some rule about length > of structs and their components. It would also help if 86s used a rational > byte order:-) > Brian O'Donnell > TCD Library > odonnllb AT tcd DOT ie It's much the same as on the 68000. The 80x86 chips work better with the proper alignment of data structures. Longs align on 4 byte boundaries, chars align on byte boundaries. I think short's align on 2 byte boundaries, but I havn't had occasion to check this in a long while. If you design your structures with all of your longs first, then words and lastly bytes you should get fairly good alignment. Of course there is something (maybe a pragma ??) that you can use to tell gcc not to optimize alignment. Hope this helps. Paul +===================================================================+ Paul Coward Whenever you find that you are on the side digisoft AT eis DOT net DOT au of the majority, it is time to reform. Mark Twain