delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/08/12/09:31:20

From: budi AT ricochet DOT net (Budi Sutardja)
Subject: Re: packed structures
12 Aug 1998 09:31:20 -0700 :
Message-ID: <35D149B8.358C.cygnus.gnu-win32@ricochet.net>
References: <000101bdc547$2b785c20$e645aace AT TomStokes>
Reply-To: aibase AT netcom DOT com
Mime-Version: 1.0
To: Tom Stokes <tstokes AT pacbell DOT net>
Cc: CYGWIN32 <gnu-win32 AT cygnus DOT com>

Tom Stokes wrote:
> 
> The size of this structure is 12 which is wrong. What am I missing?

The "packed" modifier has to be applied to the structure
not the structure's members, to do what you want.
i.e.

typedef struct a {
        long a;
        char b;
        short c;
        short d;
        } __attribute__((packed)) A;

sizeof(A) will be 9 not 12.

-- budi

	
> typedef struct HeaderTag {
>     ULONG          HeaderLength;
>     CHAR             PackingType __attribute__ ((packed));
>     USHORT         NumRows __attribute__ ((packed));
>     USHORT         PackedSize __attribute__ ((packed));
>     } HeaderType, *pHeaderType;
> 
> Also, I  have a lot of structures to pack. Is there nothing like a #pragma
> pack(1) followed later by #pragma pack()?
> 
>         Tom Stokes
> 
> -
> For help on using this list (especially unsubscribing), send a message to
> "gnu-win32-request AT cygnus DOT com" with one line of text: "help".

--
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019