title: Replacing reinterpret_cast with better alternatives?
body: <p>I have a few places in my project where I use <code>reinterpret_cast</code> to read/write an unsigned integer from a stream. Consider the following functions:</p>
  <pre><code>size_t ReadSize(std::stringstream&amp; stream) {
    char buf[sizeof(size_t)];
    stream.read(buf, sizeof(size_t));
    return *(reinterpret_cast&lt;size_t*&gt;(buf));
  }
  
  void WriteSize(std::stringstream&amp; stream, size_t n) {
    stream.write(reinterpret_cast&lt;char*&gt;(&amp;n), sizeof(size_t));
  }
  </code></pre>
  <p>I started to feel a bit uncomfortable about using reinterpret_cast, even though I've had no problems with it, so I'm wondering, is there a better alternative to this? Assuming I just have 4 bytes in the stream that are supposed to represent this integer.</p>
  <p><code>static_cast</code> isn't applicable here either, I think. Any tips?</p>
  <p>P.S. I am not currently concerned about portability or other platform-specific problems that may arise from using <code>reinterpet_cast</code>. I am writing this for a Windows machine.</p>