How to correctly cast a pointer to int in a 64-bit application?
viva64.com
viva64.com
I researched the issue in the C Language Reference Manual, document 007-0701-150, available on the web as a PDF. Here are my notes:
"In the value structure, the reference count N is a long int, which guarantees that it can also be used as a pointer to link unused values on the free list, without my having to use a cumbersome union type.
The standard says:
long ints are large enough to hold pointers in -n32 and -o32 mode. Both are
32 bits wide.
long ints are large enough to hold pointers in -64 mode. Both are 64 bits
wide.
(C Language Reference Manual, document 007-0701-150, Appendix A, Section F.3.7
"Arrays and Pointers")Assuming there are no other modes, I conclude that long ints are large enough to hold pointers, period.
As further evidence, the section titled "Integer and Floating Point Types" has a table of Storage Class Sizes which lists the size in bits for the various types in all three modes -o32, -n32, and -64. In all modes the size of a long equals the size of a pointer."