title: Is there a good way to convert from unsigned char* to char*?
body: <p>I've been reading a lot those days about <code>reinterpret_cast&lt;&gt;</code> and how on should use it (and avoid it on most cases).</p>
  
  <p>While I understand that using <code>reinterpret_cast&lt;&gt;</code> to cast from, say <code>unsigned char*</code> to <code>char*</code> is <em>implementation defined</em> (and thus <em>non-portable</em>) it seems to be no other way for <em>efficiently</em> convert one to the other.</p>
  
  <p>Lets say I use a library that deals with <code>unsigned char*</code> to process some computations. Internaly, I already use <code>char*</code> to store my data (And I can't change it because it would kill puppies if I did).</p>
  
  <p>I would have done something like:</p>
  
  <pre><code>char* mydata = getMyDataSomewhere();
  size_t mydatalen = getMyDataLength();
  
  // We use it here
  // processData() takes a unsigned char*
  void processData(reinterpret_cast&lt;unsigned char*&gt;(mydata), mydatalen);
  
  // I could have done this:
  void processData((unsigned char*)mydata, mydatalen);
  // But it would have resulted in a similar call I guess ?
  </code></pre>
  
  <p>If I want my code to be highly portable, it seems I have no other choice than copying my data first. Something like:</p>
  
  <pre><code>char* mydata = getMyDataSomewhere();
  size_t mydatalen = getMyDataLength();
  unsigned char* mydata_copy = new unsigned char[mydatalen];
  for (size_t i = 0; i &lt; mydatalen; ++i)
    mydata_copy[i] = static_cast&lt;unsigned char&gt;(mydata[i]);
  
  void processData(mydata_copy, mydatalen);
  </code></pre>
  
  <p>Of course, that is highly suboptimal and I'm not even sure that it is more portable than the first solution.</p>
  
  <p>So the question is, what would you do in this situation to have a highly-portable code ?</p>