title: C: Cast byte array to struct
body: <p>I have the problem of casting a byte array to a struct, some bytes are ignored or skipped.</p>
  
  <p>Given the following struct,</p>
  
  <pre><code>typedef struct
  {
      uint32_t id;
      uint16_t test;
      uint8_t group;
      uint32_t time;
      uint16_t duration;
      uint8_t a;
      uint8_t b;
      uint8_t c;
      uint16_t d;
      uint16_t e;
      uint8_t status;
      uint8_t x;
      uint8_t y;
  
  } testStruct_t, *PtestStruct_t;
  </code></pre>
  
  <p>I have an array with the following test data:</p>
  
  <pre><code>uint8_t pBuff = { 0x11 , 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 };
  </code></pre>
  
  <p>The casting is done as follows:</p>
  
  <pre><code>PtestStruct_t pStruct = (PtestStruct_t)pBuff;
  </code></pre>
  
  <p>Somewhere in the structure some bytes are skipped or ignored. I do not know why.
  This has been tested in Visual Studio 2012 and on a ARM processor on which this testing and debugging was made required.</p>
  
  <p>What am I missing here? I do not believe it is Endian related. It could be the compiler in both test cases, I do not know what to do in this last case.</p>
  
  <p>The bytes which are being skipped/ignored are <code>0x88</code> and <code>0x14</code></p>