title: What is *(uint32_t *) &buffer[index]?
body: <p>In some supposed-C++ code I found, I have <code>buffer</code> defined as <code>const void *buffer;</code> (it's arbitrary binary data that, I think, gets interpreted as a stream of 32-bit unsigned integers) and in many places, I have</p>
  
  <pre><code>*(uint32_t *) &amp;buffer[index]
  </code></pre>
  
  <p>where <code>index</code> is some kind of integer (I think it was <code>long</code> or <code>unsigned long</code> and got swept up in my replacing those with <code>int32_t</code> and <code>uint32_t</code> when I was making the code work on a 64-bit system).</p>
  
  <p>I recognize that this is taking the address of <code>buffer</code> (<code>&amp;buffer</code>), casting it as a pointer to a <code>uint32_t</code>, and dereferencing that, at least based on <a href="https://stackoverflow.com/a/14173495/291280">this question</a>... but then I'm confused by how the <code>[index]</code> part interacts with that or where I missed inserting the <code>[index]</code> part in between the steps I listed.</p>
  
  <p>What, conceptually, is this doing?  Is there some way I could define another variable to be a better type, with the casting there once, and then use that, rather than having this complicated expression throughout the code?  Is this actually C++ or is this C99?</p>
  
  <p><strong><em>edit:</em></strong>  The first couple of lines of the code are:</p>
  
  <pre><code>const void *buffer = data.bytes;
  if (ntohl(*(int32_t *) buffer) != 'ttcf') {
      return;
  }
  uint32_t ttf_count = ntohl(*(uint32_t *) &amp;buffer[0x08]);
  </code></pre>
  
  <p>where <code>data.bytes</code> has type <code>const void *</code>.  Before I was getting <code>buffer</code> from <code>data.bytes</code>, it was <code>char *</code>.</p>
  
  <p><strong><em>edit 2:</em></strong> Apparently, having <code>const void *buffer</code> work is not normal C (though it absolutely works in my situation), so if it makes more sense, assume it's <code>const char *buffer</code>.</p>