title: Binary read, reinterpret_cast and endianness
body: <p>I'm currently dealing with endianness-related problems.</p>
  
  <p>Let's assume that I have a big-endian file in a big-endian system.</p>
  
  <p>The first value in this file is <code>2882400152 = 0xABCDEF98</code> which is an integer 4.</p>
  
  <p>To read that value in an integer 4, <code>_myint4</code>, I simply do : </p>
  
  <pre><code>mystream.read(reinterpret_cast&lt;char*&gt;(&amp;_myint4), sizeof(_myint4))
  </code></pre>
  
  <p>The question is : what is the equivalent to read the integer 4 value in the file, in an integer 8, <code>_myint8</code> ?</p>
  
  <ul>
  <li>for a big-endian file and system ?</li>
  <li>for a little-endian file and system ?</li>
  </ul>
  
  <p>My first guess would be something like that :</p>
  
  <pre><code>mystream.read((reinterpret_cast&lt;char*&gt;(&amp;_myint8))+4, 4); // big-endian file/system
  mystream.read(reinterpret_cast&lt;char*&gt;(&amp;_myint8), 4); // little-endian file/system
  </code></pre>
  
  <p>But I'm not sure at all. What is the good way to do this ?</p>
  
  <p>IMPORTANT : I cannot use a temporary integer 4 value, I need to read directly the integer 4 in <code>_myint8</code>.</p>