Elegant way to add metainformation to char array
<p>I wanna pack some information plus some metadata in a byte array. In the following
I have 3 bytes of information which have a certain offset plus 4 bytes of metadata added
at the beginning of the packet in the end. Solution 1 I came up is pretty obvious to do
that but requires a second tmp variable which I do not really like.</p>

<pre><code>int size = 3;
int metadata = 4;

unsigned char * test = new unsigned char[size];
unsigned char * testComplete = new unsigned char[size+metadata];

test[offest1] = 'a';
test[offest2] = 'b';
test[offest3] = 'c';

set_first_4bytes(testComplete, val );           
memcpy(&amp;testComplete[metadata], test, size);
</code></pre>

<p>Another straightforward solution would be to do it the following way:</p>

<pre><code>unsigned char * testComplete = new unsigned char[size+metadata];

testComplete[offest1+metadata] = 'a';
testComplete[offest2+metadata] = 'b';
testComplete[offest3+metadata] = 'c';

set_first_4bytes(testComplete, val );
</code></pre>

<p>However, I don not like here the fact that each time I have the metadata offset to add so that I get the right index in my final packet. Is there another elegant solution which DOES not have the drawbacks of my approaches?</p>

<p>Thanks!</p>
