title: C++ pointer casting issue
body: <p>I need to pass a pointer through a scripting language which just has a double and string type, for this I only have to worry about 32-bit pointers.</p>
  
  <p>Seeing as the pointers are 32-bit, I figured doubles had enough precision to safely store the pointer, which works, however the problem arises with some pointers to stream, presumably due to multiple inheritance...and I'm really not sure how to solve it.</p>
  
  <p>Basically I've been casting the pointers to <code>unsigned</code>, and then to <code>double</code>. Then to get them back I've cast the <code>double</code> to <code>unsigned</code> and then to whatever type the pointer is.</p>
  
  <p>e.g.:</p>
  
  <pre><code>double example()
  {
      int *i = new int[100];
      return (double)(unsigned)i;
  }
  double example2(double i)
  {
      doSomething((int*)(unsigned)i);
  }
  </code></pre>
  
  <p>However with the stream types it seems to not work...</p>
  
  <pre><code>std::ofstream *fs = new std::ofstream("example.txt");
  std::cout &lt;&lt; fs &lt;&lt; std::endl;//029D1DF8 for example
  double d = (double)(unsigned)fs;
  std::ios *p = (std::ios*)(unsigned)d;
  std::cout &lt;&lt; p &lt;&lt; std::endl;//029D1DF8 same thing seems fine
  std::cout &lt;&lt; ((std::ios*)fs) &lt;&lt; std::endl;//029D1E54, opps, apparently a cast to std::ios changes the pointer to some offset!
  </code></pre>
  
  <p>Is there some way around this? I have got an idea using a map and id numbers but I'd rather avoid the cost of having such maps which may contain 1000's of entries. I much rather get the casting to work for this...</p>