title: reinterpret_cast in C++
body: <pre><code> uint32_t r,g,b;
   r = (uint32_t)145;
   g = (uint32_t)131;
   b = (uint32_t)139;
   uint32_t rgb = ((uint32_t)r &lt;&lt; 16 | (uint32_t)g &lt;&lt; 8 | (uint32_t)b);
   float rgbf = *reinterpret_cast&lt;float*&gt;(&amp;rgb);
  
   uint32_t rgbnew = *(reinterpret_cast&lt;uint32_t *&gt;(&amp;rgbf));
   uint8_t rnew = (rgbnew &gt;&gt; 16) &amp; 0x0000ff;
   uint8_t gnew = (rgbnew &gt;&gt; 8) &amp; 0x0000ff;
   uint8_t bnew = (rgbnew) &amp; 0x0000ff;
  </code></pre>
  
  <p>When I try to run this code there is segmentation fault at line</p>
  
  <blockquote>
    <p>uint32_t rgb = ((uint32_t)r &lt;&lt; 16 | (uint32_t)g &lt;&lt; 8 | (uint32_t)b);</p>
  </blockquote>
  
  <p>In fact, at one place this is running ok. At another place it is giving seg fault.</p>