title: Convert float to unsigned long to access float internals, in c #define
body: <p>I want to convert a <code>float</code> to a <code>unsigned long</code>, while keeping the binary representation of the <code>float</code> (so I do <em>not</em> want to cast <code>5.0</code> to <code>5</code>!).</p>
  
  <p>This is easy to do in the following way:</p>
  
  <pre><code>float f = 2.0;
  unsigned long x = *((unsigned long*)&amp;f)
  </code></pre>
  
  <p>However, now I need to do the same thing in a <code>#define</code>, because I want to use this later on in some array initialization (so an [inline] function is not an option).</p>
  
  <p>This does not compile:</p>
  
  <pre><code>#define f2u(f) *((unsigned long*)&amp;f)
  </code></pre>
  
  <p>If I call it like this:</p>
  
  <pre><code>unsigned long x[] = { f2u(1.0), f2u(2.0), f2u(3.0), ... }
  </code></pre>
  
  <p>The error I get is (logically):</p>
  
  <pre><code>lvalue required as unary ‘&amp;’ operand
  </code></pre>
  
  <hr>
  
  <p><strong>Note:</strong> One solution that was suggested below was to use a <code>union</code> type for my array. However, that's no option. I'm actually doing the following:</p>
  
  <pre><code>#define Calc(x) (((x &amp; 0x7F800000) &gt;&gt; 23) - 127)
  unsigned long x[] = { Calc(f2u(1.0)), Calc(f2u(2.0)), Calc(f2u(3.0)), ... }
  </code></pre>
  
  <p>So the array really will/must be of type <code>long[]</code>.</p>