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: struct packing reliability?


Hi,

I'm not sure this will help, but have you tried

#pragma pack(1)

prior to your packed declarations?  I have many packed structures that come 
out to the correct size, and that may be the difference.

be sure to restore default behavior after the packed section with

#pragma pack()

Regards,

Andrew Lees.

On Wed, 27 Feb 2002 13:28, you wrote:
> Hello all;
>
> I'm trying to make a consistent C interface to various sets of hardware
> registers on the Gameboy Advance by using packed structs: for instance,
> there is an area of memory which stores an array of 128 64-bit 'objects'
> which look like this:
>
>   #define PACKED __attribute__((packed))
>   ...
>   struct _gba_ObjEntry
>   {
>       /****** attribute 0 */
>
>       /* Y position of Obj */
>       unsigned int y : 8;
>
>       /* Whether to apply rotation and scaling */
>       unsigned int rotateAndScale : 1;
>
>       /* */
>       unsigned int sizeDouble : 1;
>
>       /* */
>       unsigned int alphaMode : 2;
>
>       /* */
>       unsigned int mosaic : 1;
>
>       /* Indicates that a Obj is 256 colour, not 16 */
>       unsigned int is256colour : 1;
>
>       /* Lower two bits of Obj size constant */
>       enum { Square, Tall, Wide } PACKED shape : 2;
>
>       /****** attribute 1 */
>
>       /* X position of Obj */
>       unsigned int x : 9;
>
>       union
>       {
>   	  unsigned int rotationIndex : 5;
> 	  struct
>   	  {
> 	      unsigned int unused : 3;
>
> 	      unsigned int x : 1;
> 	      unsigned int y : 1;
> 	  } PACKED
> 	  flipFlags;
>       } PACKED
>       transform;
>
>       /* Upper two bits of Obj size constant */
>       enum { Size8, Size16, Size32, Size64 } PACKED size : 2;
>
>       /****** attribute 2 */
>
>       /* The index of the tile in */
>       unsigned int firstCharacterIndex : 10;
>
>       /* Higher priority Objs are plotted over lower priority Objs */
>       unsigned int priority : 2;
>
>       /* Which palette to use, only relevant for 16 colour Objs */
>       unsigned int paletteNumber : 4;
>
>       /****** attribute 3 */
>
>       unsigned int rotationInformation : 16;
>
>   } PACKED;
>


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