When I have a user defined type like the following:
typedef struct MyData_t {
uint16_t val;
...
} MyData;
And a simple array that I want to use to store different types of structures in:
uint8_t buffer[];
And I then want to create a structure pointer that uses the array to store the data of that structure:
MyData* freelist = (MyData*) buffer;
Then I get the MISRA 2012 Error:
Note 9087: cast performed between a pointer to object type and a pointer to a different object type [MISRA 2012 Rule 11.3, required]
This rule says because of possible alignment issues it is never safe to cast pointers between different types of objects. My question is: How common is it in an embedded environment for compilers to cause any issues in this case? And how could I prevent these issues when forced to keep the implementation concept (about the buffer array that stores different types of objects)?