Like Sean said, it's useful for manipulating pointers as if they were numbers.
Here's an example from the MSDN website that uses it to implement a basic hash function (note that this uses an unsigned int rather than a long, but the principle is the same)
unsigned short Hash( void *p ) {
unsigned int val = reinterpret_cast<unsigned int>( p );
return ( unsigned short )( val ^ (val >> 16));
}
This takes an arbitrary pointer, and produces an (effectively) unique hash value for that pointer - by treating the pointer as an unsigned int
, XORing the integral value with a bit-shifted version of itself, and then truncating the result into an unsigned short
.
However, like everyone else has said, this is very dangerous and should be avoided.