Packing data into a buffer portably
<p>I have to place several integer values into a (32 byte) buffer, where each integer must be at a specific place in the buffer (I'm going to use the data in OpenGL VBOs).</p>

<p>The way I'm doing it now is kind of ugly. All the content is supposed to be placed at the address buf2. Don't bother looking at the values I'm assigning to the buffer, as those are irrelevant to the problem.</p>

<pre><code>    uint32_t *const coords      = reinterpret_cast&lt;uint32_t *&gt;(buf2 + CoordDataOff);
    uint16_t *const texcoords   = reinterpret_cast&lt;uint16_t *&gt;(buf2 + TcoordDataOff);
    uint32_t *const color       = reinterpret_cast&lt;uint32_t *&gt;(buf2 + ColorDataOff);

    coords[0] = x + bearing[0]; // left
    coords[1] = y + bearing[1] - 64*(tcoords[3] - tcoords[1]); // bottom
    coords[2] = x + bearing[0] + 64*(tcoords[2] - tcoords[0]); // right
    coords[3] = y + bearing[1]; // top
    copy_n(tcoords, 4, texcoords);
    *color = c.color;
</code></pre>

<p>Is there any nicer, portable way of accomplishing it?</p>
