title: Is it safe to reinterpret_cast an integer to float?
body: <p>Note: I mistakenly asked about <code>static_cast</code> originally; this is why the top answer mentions <code>static_cast</code> at first.</p>
  
  <p>I have some binary files with little endian float values. I want to read them in a machine-independent manner. My byte-swapping routines (from SDL) operate on unsigned integers types.</p>
  
  <p>Is it safe to simply cast between ints and floats?</p>
  
  <pre><code>float read_float() {
      // Read in 4 bytes.
      Uint32 val;
      fread( &amp;val, 4, 1, fp );
      // Swap the bytes to little-endian if necessary.
      val = SDL_SwapLE32(val);
      // Return as a float
      return reinterpret_cast&lt;float &amp;&gt;( val );  //XXX Is this safe?
  }
  </code></pre>
  
  <p>I want this software to be as portable as possible. </p>