I came up with a little puzzle/challenge for C++, so for those interested, my challenge to you is this:
Using any C++ constructs, other than any of the casting constructs*, reimplement the following code:
int i = someIntValue();
int *pint = reinterpret_cast<int*>(i)
Or in words, find a way to reinterpret_cast an integer into a pointer without casting (implicitly, or explicitly!). You may assume that
I hope to be surprised by answers I hadn't thought of
* with casting constructs, I mean any form of implicit casts (e.g. int to long int), C-style casts (e.g.
(int*)i) and C++-style casts (
e.g. reinterpet_cast<int*>(i)); and also any functions/macro's/API calls (such as STL implementations) which rely internally on casts.