This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am using the ARM compiler TI 5.0.5. I am porting a module from an 8-bit target to a 32 bit TiVa target. Simplified (I actually have structures of structures, where some structures are not modulo 32 bits) I have a structure that looks like:
struct s {
UINT8 x;
UINT16 y;
UINT8 z;
};
So the 8-bit compiler might put x, y and z at 0x100, 0x101 and 0x103 respectively. This takes up 4 bytes.
I am assuming that the 32-bit ARM compiler would put these at 0x100, 0x104 and 0x108 respectively, filling to the 32-bit boundary. (I am testing that now.)
I found in the compiler UG that you can align a structure on different boundaries, but found nothing talking about not letting the compiler stuff hidden bytes in a structure to align members to 32-bit boundaries.
Is there a way to get the ARM compiler to align structure elements as the previous 8-bit compiler does?
John
Apparently just setting the "--align_structs=1" does the trick. My structures look just like the 8-bit structures now.
Unfortunately this setting does not apply to unions, so a union defined as:
union {
struct {unsigned out0:1; .... unsigned out15};
unsigned short i;
unsigned char b[2];
} u;
ends up having a size of 4, rather than of 2. If you have this union stuffed into the middle of a structure, it will bloat out the structure 2 bytes.
It is the bit field structure that is killing me here, as a bit field structure is 4 bytes long, regardless of how many bits are defined.
My question has evolved to: Is there a way to get a bit-field structure to allocate the minimume bytes necessary to store the bit field? In the case above, that would be two bytes.
I think you want packed structures, and --align_structs does not do that. To quote the compiler manual
Only a minimum alignment is set, the data structures are not packed.
You need to use the #pragma PACK, or the gcc __attribute__((__packed__)). Please see all the details in the compiler manual.
Thanks and regards,
-George
Thanks for the response.
I am now running arm_5.1.1
using
#pragma PACK (2)
or
#pragma PACK
I get the message "#163-D: unrecognized #pragma"
Is this option known to be supported in 5.1.1?
I apologize for the confusion over PACK. I'm currently looking into how that happened.
The __attribute__((__packed__)) still works. That is a GCC language extension, so you have to build with the option --gcc to use it.
Thanks and regards,
-George
Thanks for looking into the PACK pragma.
I will try the gcc extensions.
Will the gcc extensions change how my current code is compiled? Code that does not use gcc extensions?
John Osen said:Will the gcc extensions change how my current code is compiled?
No. Taking advantage of any extension always requires you to write something beyond the base language specification in your source.
Thanks and regards,
-George
Unfortunately while updating the compiler, I chose to update CCS 5.4 -> 5.5 and emulator drivers. Now I can compile, but not emulate :'-(
It will take some time before I can say your gcc suggestion fixed the problem.