title: Casting Function Pointer to Integer in C++
body: <p>I have an array of unsigned integers that need to store pointers to data and functions as well as some data.  In the device I am working with, the sizeof pointer is the same as sizeof unsigned int.  How can I cast pointer to function into unsigned int?  I know that this makes the code not portable, but it is micro controller specific.  I tried this:</p>
  
  <pre><code>stackPtr[4] = reinterpret_cast&lt;unsigned int&gt;(task_ptr);
  </code></pre>
  
  <p>but it give me an error "invalid type conversion"</p>
  
  <p>Casting it to void pointer and then to int is messy.</p>
  
  <pre><code>stackPtr[4] = reinterpret_cast&lt;unsigned int&gt;(static_cast&lt;void *&gt; (task_ptr));
  </code></pre>
  
  <p>Is there a clean way of doing it?</p>
  
  <p>Edit - task_ptr is function pointer <code>void task_ptr(void)</code></p>
  
  <p>Love Barmar's answer, takes my portability shortcoming away.  Also array of void pointer actually makes more sense then Unsigned Ints.  Thank you Barmar and isaach1000.</p>
  
  <p>EDIT 2:  Got it, my compiler is thinking large memory model so it is using 32 bit pointers not 16 bit that I was expecting (small micros with 17K total memory).</p>