[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



Nu kan man komme om meget ved at have lidt viden når struct's skrives. Ved 
at bytte på enkelte værdier vil det give det samme vil jeg mene. 

Hvis du f.eks. i en struct har 4 stk. UInt32 og 4 stk. UInt32 er det værste 
du kan gør dette.

typedef struct
{
UInt8 v1;
UInt32 v2;
UInt8 v3;
UInt32 v4;
UInt8 v5;
UInt32 v6;
UInt8 v7;
UInt32 v8;
} MyStruct;


Altså byt om, og vær glad. 
Kender ingen compiler eller precompiler der kan lave denne ombytning. Men 
har heller ikke checket op de seneste versioner.


typedef struct
{
     UInt32 file_size;
     UInt32 reserved;
     UInt32 data_offset;
     UInt8 signature[2];
 } Header;


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 ?
> 
> Anders
> 
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx



 
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] *