Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!microsoft!paulc From: paulc@microsoft.UUCP (Paul Canniff 2/1011) Newsgroups: comp.lang.c Subject: Re: Structure padding Message-ID: <1265@microsoft.UUCP> Date: 9 Apr 89 00:22:56 GMT References: <440@front.se> <518@lakesys.UUCP> Reply-To: paulc@microsoft.UUCP (Paul Canniff 2/1011) Organization: Microsoft Corp., Redmond WA Lines: 25 In article <440@front.se> zap@front.se (Svante Lindahl) writes: |Consider a struct consisting of a few character arrays, for example: | stuct foo { | char bar[3]; | char baz[6]; | char frotz[4]; | } fred; |I need to know if I can safely assume that there will not be any |padding between the arrays. Don't unless you have a real size problem. But read on for details ... Microsoft C does indeed have options to enable or disbale padding of structures to WORD slignment, for faster operations on Intel's processors. The default is WORD alignment. The option can be set to BYTE, DWORD or WORD. (See /Zp in MSC user's ref). But ... even in the Intel world, the example above would not be effected since the arrays are of type char, and will (theoretically) be accessed a byte at a time. So the compiler doesn't bother to word-align the elements. The moral ... you can probably assume byte alignment, since most C compilers will have to aimplement it (at whatever cost to performance), but make a note of it in your porting instructions!