GP2X Gcc Struct Packing.


MadDog

Member
Joined
Mar 4, 2006
Messages
262
Age
54
Location
UK
Website
www.maddoggames.com
I can't get -fpack-struct=1 or #pragma pack(push,1) to work on some structs that I need to be byte packed. They all seem to be rounded upto to multiples for 4. Not checked to see what the spacing between the members is but on other compilers when you pack to a byte no rounding up is done.

Best go to bed now. :(

( too much fun coding gp2x, not enough time in the day! )
 
MadDog posted on May 9 2006 at 12:22 AM said:
I can't get -fpack-struct=1 or #pragma pack(push,1) to work on some structs that I need to be byte packed. They all seem to be rounded upto to multiples for 4. Not checked to see what the spacing between the members is but on other compilers when you pack to a byte no rounding up is done.
Arm only allows reading words (32bit) on 32 bit boundaries and half-words (16bit) on 16 bit boundaries. Only 8 bit values can be non-aligned. It wouldn't surprise me if gcc is overly strict and refuses to pack structues just in case you try to fudge it with casts.
 
Last edited by a moderator:
I've had the same problem - GCC seemed to completely ignore this:

Code:
#pragma pack(push,1)
typedef struct BMP_HEADER {
...
} BMP_HEADER;

but it seems to do as it's told when done this way:

Code:
typedef struct BMP_HEADER {
...
} __attribute__ ((aligned (1), packed)) BMP_HEADER;

Have the tried the later?
 
Squidge posted on May 9 2006 at 06:26 AM said:
I've had the same problem - GCC seemed to completely ignore this:

Code:
#pragma pack(push,1)
typedef struct BMP_HEADER {
...
} BMP_HEADER;

but it seems to do as it's told when done this way:

Code:
typedef struct BMP_HEADER {
...
} __attribute__ ((aligned (1), packed)) BMP_HEADER;

Have the tried the later?

No but I will. Have to say when I saw the method I used in a doc on the net I did think to my self it did not look right. Its the way MS do it. The second way is what i've seen with ps2 and SN compilers (based on gcc) and what I expected when I checked the gcc docs. I'll go give it a go. Have to say the alignment is part of the prob, but my struct is two shorts and one byte and i'm casting it to a chunk of memory so i'm in for trouble even if I do get the packing to work. :( But it was rounding it up to 8 bytes not six as I would have though it would do to ensure that the next element in that array is aligned corectly for the first 16bit member of my struct.

Sounds like its like the old 68k was, so many years on x86 chips have taught me bad habbits. ;)
 
Last edited by a moderator:
MadDog posted on May 9 2006 at 12:22 AM said:
I can't get -fpack-struct=1 or #pragma pack(push,1) to work on some structs that I need to be byte packed. They all seem to be rounded upto to multiples for 4. Not checked to see what the spacing between the members is but on other compilers when you pack to a byte no rounding up is done.

Best go to bed now. :(

( too much fun coding gp2x, not enough time in the day! )
I take it my response here wasn't any help then, or did it just not work?
 
Last edited by a moderator:
Back
Top