Click here to Skip to main content
15,924,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please when is it best/right to use the new data types i.e the _PTR types so that a code can compile to both 32 and 64 bit code?

Please I really am at loss as to when to so do.Please help.I have already read documentation and still did not get it.
Posted
Comments
Gbenbam 18-Feb-14 14:42pm    
Please see related question here:

http://www.codeproject.com/Questions/729713/Can-the-following-code-run-on-64bit-system?cmt=587930#cmt2_729713



My excessive use of INT_PTR types in the code is due to the fact that I don't really know when to use the _PTR types?

This was answered some time ago on StackOverflow:
DWORD_PTR, INT_PTR, LONG_PTR, UINT_PTR, ULONG_PTR When, How and Why?[^]
They have nothing to do with a single compiled object running on both 32 and 64 bit platforms (except for huge arrays as noted in the reference), they just allow the compiler to use the correct size storage for pointers when compiling for 32 bit or 64 bit platforms. The source code doesn't need to change, the compiler does "the right thing".
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-14 21:21pm    
Correct, and the good point, a 5.
—SA
All the new *_PTR types are meant to be used for dealing with those windows functions that formerly, incorrectly, used integer types such as LONG or DWORD instead, but meant to use those values as pointers, array subscripts, or memory offset values. These definitions didn't cause a problem in 32 bit systems, but fail to compile or run on 64 bit systems, because pointers or pointer differences in 64 bit can't fit into a DWORD or LONG.

Technically, INT_PTR and LONG_PTR are different from the other *_PTR types in that they can hold negative values. These two types are equivalent to the Microsoft type SSIZE_T; or the C++ standard type std::ptrdiff_t. You need that type for any variable that may be used to store the difference between two memory locations, or the difference between the size of one object and the size of another object in memory. Note that it is very, very rare in common programs to ever, truly, need a variable of this type.

UINT_PTR and ULONG_PTR appear to be meant for uses where you need an array subscript, an offset to a memory base address, or the size of an object in memory. The Microsoft type SIZE_T, and the C++ standard type std::size_t are defined exactly the same, and fill the same role.

DWORD_PTR appears to be the only of the new *PTR types that fulfill the role implied by the trailing 'PTR': that is, store an actual pointer.

There is no reason at all for you to use any of these *_PTR types, as they are equivalent to standard pointers, std::size_t, and std::ptrdiff_t respectively.
 
Share this answer
 
Comments
Gbenbam 19-Feb-14 11:39am    
This is the most satisfying of all solutions that I have got on this so far.I owe you an all expense paid trip to the moon.Thanks a trillion times.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900