29-09-2011, 10:27 AM
Hi
is packing of structures allowed within Misra C?
I only wish to use the structure to overlay a generic byte array, which is populated from an external interface serialy. However the structure has 7 bytes but without packing has 8.
What i want is to be able to index into the generic array as such
sCFG *ptr = &genericArray[0];
for(i=0u; i< 10u; i++){
ptr[i].CFG0 = 10u;
..etc..
}
But because without packing the struct is 1 byte larger, i will end up misaligned.
So basically can i pack my structure to acheive this goal?
Thank you
James
FYI
typedef struct{
u8 CFG0;
u8 CFG1;
u8 CFG2;
u8 CFG3;
u8 CFG4;
u8 CFG5;
u8 CFG6;
}sCFG ;
is packing of structures allowed within Misra C?
I only wish to use the structure to overlay a generic byte array, which is populated from an external interface serialy. However the structure has 7 bytes but without packing has 8.
What i want is to be able to index into the generic array as such
sCFG *ptr = &genericArray[0];
for(i=0u; i< 10u; i++){
ptr[i].CFG0 = 10u;
..etc..
}
But because without packing the struct is 1 byte larger, i will end up misaligned.
So basically can i pack my structure to acheive this goal?
Thank you
James
FYI
typedef struct{
u8 CFG0;
u8 CFG1;
u8 CFG2;
u8 CFG3;
u8 CFG4;
u8 CFG5;
u8 CFG6;
}sCFG ;
<t></t>