- This topic has 0 replies, 1 voice, and was last updated 2 weeks, 2 days ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
(This message was transferred over from our old forum)
Posted August 19, 2015
By Todd DeBoer
[hr]
On 10/30/2009 wella asked, “I think that the compiler could not optimise the structure arrangement.
If you do it manualy, you can save some space.
Below are two identical structs but the second one has all 8bits items at the end.
uint32_t s0 = sizeof(I2C_Request0);
uint32_t s1 = sizeof(I2C_Request1);
This example was compiled by gcc version 4.4.1 (Sourcery G++ 4.4-180) and the
s0 = 32, s1 = 24,
8 byte save is quite interresting.
typedef struct {
TUInt8 iAddr; // 7-bit address of I2C device
TUInt16 iSpeed; // in kHz
TUInt8 *iWriteData; // 0 or NULL value means no write action
TUInt8 iWriteLength; //————> ??????
TUInt32 iWriteTimeout;
TUInt8 *iReadData; // 0 or NULL value means no read action
TUInt8 iReadLength;//————> ??????
TUInt32 iReadTimeout;
volatile T_uEZI2CStatus iStatus;
} I2C_Request;
typedef struct {
TUInt8 *iWriteData; // 0 or NULL value means no write action
TUInt32 iWriteTimeout;
TUInt8 *iReadData; // 0 or NULL value means no read action
TUInt32 iReadTimeout;
volatile T_uEZI2CStatus iStatus;
TUInt16 iSpeed; // in kHz
TUInt8 iWriteLength;
TUInt8 iReadLength;
TUInt8 iAddr; // 7-bit address of I2C device
} I2C_Request1;”
[hr]
(Follow up post)
Answered:
Right. Many compilers won’t rearrange the entries in a structure and will only pad each individual entry for alignment, but they will combine them based on order (8-bit back to back will be combined). Given our previous converstation about making these TUInt8’s larger, this will nullify the setup. But you are correct, we probably should consider this when first building the structures.