title: Cast increases required alignment of target type
body: <p>I am programming on ARM and have the following code snippet (in C):</p>
  
  <pre><code>struct data {
     int x;
     char y[640];
  };
  unsigned int offset = 819202;
  char *buf; // buf is assigned an address elsewhere in the code
  struct data * testdata = (struct data *)(buf + offset) 
  </code></pre>
  
  <p>I get the following compilation error:</p>
  
  <blockquote>
    <p>error: cast increases required alignment of target type [-Werror=cast-align]</p>
  </blockquote>
  
  <p><code>testdata</code> pointer needs to point to the portion of memory that contains an array of data of type <code>struct data</code>. So I need a pointer so that later I can apply an index to <code>testdata</code>. Offset is hard coded in the program. <code>buf</code> is received as shared memory from another process.</p>
  
  <p>For example, later in code I have:</p>
  
  <pre><code>testdata[index].x = 100;
  </code></pre>
  
  <p>I have seen some examples on SO but I'm not sure what is the correct way to handle this. Any suggestions ?</p>