title: Convert/extract ints from a char array
body: <p>I got a cstring, originating from a call from gzread. I know the data is blocks, and each block is consisting of an unsigned int, char, int and unsigned short int.</p>
  
  <p>So I was wondering what the standard way of splitting this cstring into the appropriate variables is.</p>
  
  <p>Say the first 4 bytes, is a unsigned int, the next byte is char, the next 4 bytes is signed int, and the last 2 bytes are unsigned short int.</p>
  
  <pre><code>//Some pseudocode below which would work
  char buf[11];
  unsigned int a;
  char b;
  int c;
  unsigned short int d;
  </code></pre>
  
  <p>I guess I could memcpy, with appropriate offsets.</p>
  
  <pre><code>memcpy(&amp;a, buf, sizeof(unsigned int));
  memcpy(&amp;b, buf+4, sizeof(char));
  memcpy(&amp;c, buf+5, sizeof(int));
  memcpy(&amp;d, buf+9, sizeof(unsigned short int));
  </code></pre>
  
  <p>Or is it better to use some bitoperators? Like shifting and masking.</p>
  
  <p>Or would it be better to gzreading all 11 bytes directly into some struct, or is that even possible? Is the memory layout of a struct fixed, and will this work with gzread?</p>