title: MISRA-C: Is it safe to cast a char array to a structure pointer?
body: <p>When I have a user defined type like the following:</p>
  <pre><code>typedef struct MyData_t {
    uint16_t val;
    ...
  } MyData;
  </code></pre>
  <p>And a simple array that I want to use to store different types of structures in:</p>
  <pre><code>uint8_t buffer[];
  </code></pre>
  <p>And I then want to create a structure pointer that uses the array to store the data of that structure:</p>
  <pre><code>MyData* freelist = (MyData*) buffer;
  </code></pre>
  <p>Then I get the MISRA 2012 Error:</p>
  <blockquote>
  <p>Note 9087: cast performed between a pointer to object type and a pointer to a different object type [MISRA 2012 Rule 11.3, required]</p>
  </blockquote>
  <p>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)?</p>