This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Re: packed structures
- To: "Tom Stokes" <tstokes at pacbell dot net>
- Subject: Re: packed structures
- From: Andreas Degert <ad at papyrus dot hamburg dot com>
- Date: 12 Aug 1998 11:30:43 +0200
- Cc: "CYGWIN32" <gnu-win32 at cygnus dot com>
- References: <000101bdc547$2b785c20$e645aace@TomStokes>
"Tom Stokes" <tstokes@pacbell.net> writes:
> The size of this structure is 12 which is wrong. What am I missing?
[...]
try the following (compile and execute or compile to .s):
------------------------------------------
typedef struct HeaderTag
{
unsigned long HeaderLength;
char PackingType __attribute__ ((packed));
unsigned short NumRows __attribute__ ((packed));
unsigned short PackedSize __attribute__ ((packed));
} __attribute__ ((packed)) HeaderType;
#define offset(f) (int)&(((HeaderType*)0)->f)
int main(void)
{
printf("%d,%d,%d,%d\n",offset(PackingType),offset(NumRows),
offset(PackedSize),sizeof(HeaderType));
return 0;
}
--------------------------------------------
Notice the added attribute after the closing brace. Without that the
whole structure is padded with 3 additional bytes.
ciao
Andreas
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".