This is too crude. Just let the compiler do the work for you, enable warning 4302 so it will tell you when a pointer value gets truncated. Put the #pragma in a good place, the pre-compiled header file would be ideal. Or specify the /we4302
compiler option.
#pragma warning(default:4302)
int main()
{
int* p = 0;
long bad = (long)p; // C4302: 'type cast' : truncation from int* to long
return 0;
}
The /Wp64 compile option can be useful as well, for a sniff anyway, but it has problems.