title: C++ std::string and NULL const char*
body: <p>I am working in C++ with two large pieces of code, one done in "C style" and one in "C++ style".</p>
  
  <p>The C-type code has functions that return const char* and the C++ code has in numerous places things like </p>
  
  <pre><code>const char* somecstylefunction();
  ...
  std::string imacppstring = somecstylefunction();
  </code></pre>
  
  <p>where it is constructing the string from a const char* returned by the C style code.</p>
  
  <p>This worked until the C style code changed and started returning NULL pointers sometimes.  This of course causes seg faults.</p>
  
  <p>There is a lot of code around and so I would like to most parsimonious way fix to this problem.  The expected behavior is that imacppstring would be the empty string in this case.  Is there a nice, slick solution to this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>The const char* returned by these functions are always pointers to static strings.  They were used mostly to pass informative messages (destined for logging most likely) about any unexpected behavior in the function.  It was decided that having these return NULL on "nothing to report" was nice, because then you could use the return value as a conditional, i.e.</p>
  
  <pre><code>if (somecstylefunction()) do_something;
  </code></pre>
  
  <p>whereas before the functions returned the static string "";</p>
  
  <p>Whether this was a good idea, I'm not going to touch this code and it's not up to me anyway.</p>
  
  <p>What I wanted to avoid was tracking down every string initialization to add a wrapper function.</p>