[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Byte alignment



On Thu, Jun 20, 2002 at 01:00:56PM +0000, Anders Larsen wrote:
> Hej allesammen
> 
> Jeg har følgende definition:
> 
> <CODE SNIPPET BEGIN>
> typedef unsigned char UInt8;
> typedef unsigned int UInt32;
> typedef struct
> {
>     UInt8 signature[2];
>     UInt32 file_size;
>     UInt32 reserved;
>     UInt32 data_offset;
> } Header;
> </CODE SNIPPET END>
> 
> og når man lægger det hele sammen skulle Header gerne fylde 14 bytes. Det 
> gør den bare ikke. Den fylder 16 bytes og jeg vil gætte på at det er fordi 
> gcc bruger 32 bit alignment.
> Jeg fandt engang ud af hvordan man satte alignment til 8 bits men jeg kan 
> ikke finde ud af det igen.
> 
> Er der nogen der kan hjælpe ?
Jeps. Hvis du istedet for skriver noget i stil med:

typedef struct
{
  UInt8 signature[2];
  UInt32 file_size;
  UInt32 reserved;
  UInt32 data_offset;
} __attribute__ ((packed)) Header;

Jeg er ikke 100% sikker på at syntaksen er korrekt når der er tale om en
typedef af en anonym struct, men hvis du flytter Header op til efter
struct, og fjerne typedef, så virker det i hvertfald.

-- 
/-----------------------------------------------------\
| Klaus S. Madsen      | "Failure is not an option... |
| ICQ: 45400164        |  It comes bundled with your  |
| www.hjernemadsen.org |  Microsoft products!"        |
\-----------------------------------------------------/


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *