title: Copy variables into one buffer and read it
body: <p>I created three buffers and variables and copied every variable to the according buffer.</p>
  
  <p>Then I took the pointers from the buffer and printed it.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
  
      // Buffers.
      unsigned char a_buffer[sizeof(int)];
      unsigned char b_buffer[sizeof(int)];
      unsigned char c_buffer[sizeof(float)];
  
      // Variables ressources.
      int a = 65500;
      int b = 32000;
      float c = 3.14;
  
      // Variables pointers.
      int *aa = NULL;
      int *bb = NULL;
      float *cc = NULL;
  
      /* Copy variables to buffer. */
      memcpy(a_buffer, &amp;a, sizeof(int));
      memcpy(b_buffer, &amp;b, sizeof(int));
      memcpy(c_buffer, &amp;c, sizeof(float));
  
      /* Set pointers. */
      aa = (int*) a_buffer;
      bb = (int*) b_buffer;
      cc = (float*) c_buffer;
  
      // Print values.
      printf("%i %i %f\n", *aa, *bb, *cc);
  
      return 0;
  }
  </code></pre>
  
  <p>Output: <code>65500 32000 3.140000</code></p>
  
  <p>Now I like to store these variables into one buffer and wrote this.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
  
      // Buffer.
      unsigned char buffer[sizeof(int) + sizeof(int) + sizeof(float)];
  
      // Buffer pointer (first object).
      unsigned char *buf_ptr = buffer;
  
      // Variables ressources.
      int a = 65500;
      int b = 32000;
      float c = 3.14;
  
      // Variables pointers.
      int *aa = NULL;
      int *bb = NULL;
      float *cc = NULL;
  
      /* Copy variables to buffer. */
      uint16_t cur = 0;
      memcpy(buf_ptr + cur, &amp;a, sizeof(int));
      cur += sizeof(int);
      memcpy(buf_ptr + cur, &amp;b, sizeof(int));
      cur += sizeof(int);
      memcpy(buf_ptr + cur, &amp;c, sizeof(float));
      cur += sizeof(float);
  
      /* Set pointers. */
      cur = 0;
      aa = (int*) buf_ptr + cur;
      cur += sizeof(int);
      bb = (int*) buf_ptr + cur;
      cur += sizeof(int);    
      cc = (float*) buf_ptr + cur;
      cur += sizeof(float);
  
      // Print values.
      printf("%i %i %f\n", *aa, *bb, *cc);
  
      return 0;
  }
  </code></pre>
  
  <p>Output: <code>65500 2054246226 0.000000</code></p>
  
  <p>The first variable is correct, the second changes always, and the third is always zero.</p>
  
  <p>What is the correct way to do it?</p>