Code: Select all
short a = (short) &V; // OK, but value will be truncated
long a = (long)&V; // OK too, and value may still be truncated too on some systems!
Now, in 64bit: AFAIK in linux int is still 32bit but long is 64bit (to keep with old tradition of storing pointers in long type), so it is possible to convert between ptr and long both in 32bit linux and 64bit one.
But in windows long is still 32bit (also for compatibility:) and you have to use 'long long' to get 64bit int.
You may also get by some other type probably, like intptr_t or int64 that explicitly guarantee enougth size to fit pointer. Look it up in documentation for compiler.
But keep in mind that: constants need to have proper type too, like 0xFFFFFFFFFFl (note l) or they may be truncated (compiler will issue warning typically), printf() formats also require proper size (%p would work for pointers) etc. etc.
All that said, if you use int of proper size then storing there pointers are absolutely OK.