This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Packed structures


Hi
You could try:

struct XXXX {
.
.
.
} __attribute__ ((packed));  

/Gusti
> -----Original Message-----
> From:	John Love-Jensen [SMTP:eljay@adobe.com]
> Sent:	Wednesday, July 02, 2003 1:44 PM
> To:	Phil Prentice; gcc-help@gnu.org; gcc@gnu.org
> Subject:	Re: Packed structures
> 
> Hi Phil,
> 
> I've used this technique...
> 
> typedef char byte;
> struct IORegisters {
>   volatile byte setindata[1]; // write only!
>   byte nop0[6]; // Do not use!!!
>   const volatile byte getinready[1]; // read only!
>   const volatile byte getoutdma[4]; // read only!
>   volatile byte setoutdma[4]; // write only!
>   byte nop1[1]; // Do not use!!!
>   volatile byte setindma[4]; // write only!
>   const volatile byte getoutdata[1]; // read only!
>   byte nop2[1]; // Do not use!!!
>   const volatile byte getoutready[1]; // read only!
> };
> 
> IORegisters* theRegisters = (IORegisters*)0xC00000;
> 
> If you are using C++, you can add helpers...
> 
>   typedef unsigned long int nat32; // Natural 32-bit number.
>   void* getOutDma() {
>     while(getoutready[0] != 0x00)
>       continue;
> 
>     return (void*)
>       ( (nat32(getoutdma[0] & 0xFF) << 24)
>       | (nat32(getoutdma[1] & 0xFF) << 16)
>       | (nat32(getoutdma[2] & 0xFF) << 8)
>       | nat32(getoutdma[3] & 0xFF)
>       );
>     }
>     ... et cetera ...
> 
> --Eljay
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]