Using ARM and RTX on MCB2300, I have the following struct defined from an extern file storage array:
typedef struct choreoEvent { U8 flags; U16 leftover; U8 disable; U16 cueid; U32 time; char name[6]; U32 circuit; char display[12]; } choreoEvent_t;
This is 32 bytes in storage, but sizeof is reporting it as 36 bytes, and trying to access name starts 2 bytes off.
Is it doing alignment on the U8's or something? I can't restructure it because it's being read form an external file stream. Anyone see what's happening?
Compiler struct padding issue - I guess. You can use the "offsetof" operator to see which member was "shifted" !
That was my guess as well, but it doesn't help, knowing it's off I still can't use the event.name construct because it's pointing to the wrong place. I've been looking through docs, seeing if this padding is mentioned anywhere, and if there's a way to turn it off. Haven't found it yet...
Compiler struct padding issue - I guess.
Bit worrying when a professional has to guess at the functionality of their tools :(
Anyway. Unless there is packing taking place, padding of elements with the structure is occuring.
Look at #pragma pack
Well, I cannot see the good man's code and I cannot read minds so I only expressed my opinion about the most likely cause. Is that bad?
www.keil.com/.../armccref_cjafeedg.htm
That was it, thanks you saved me a few hours going through the manuals...
You're welcome.
sizeof() reporting wrong size of struct
That's a very common misconception. No, the size reported by sizeof is not wrong. It's exactly correct. What's wrong here is your expectation of what it should be reporting.
And no, reading data structures from outside your C program directly into a struct is not how you do it. You may believe that #pragma pack is the solution to your problem --- well, it's not, and that's because the problem is not the one you think it is. For the proper solution, look up "serialization".
http://www.keil.com/forum/18859/
http://www.keil.com/forum/docs/thread20238.asp