What is the meaning of __ptr32 and __ptr64?

As described in this MSDN article , Microsoft has these two type annotations for declaring native pointers on different architectures. However, on the second line:

On a 32-bit system, a pointer declared with __ptr64 is truncated to a 32-bit pointer. On a 64-bit system, a pointer declared with __ptr32 is forced into a 64-bit pointer.

It sounds like a declaration does not matter; if architecture in any case overrides the __ptrXX default declaration, what is the __ptrXX marking point in the first place?

I see that this answer says it is for interop, but if the declarations are essentially overridden as above, how does this help with interop?

+4
source share
1 answer

There is a big difference between declaring and assigning a 32-bit pointer and actual use. In other words, dereferencing a pointer. If you do this in a 64-bit process, then there is no other option but to sign it before the 64-bit pointer. This is what coercion means. This may happen by accident, but you must be very lucky. It just doesn't make sense to try.

The __ptr32 declaration point is described in this related answer, it only makes sense when interacting with a 32-bit process. Which uses 32-bit pointers. This is not often.

+1
source

Source: https://habr.com/ru/post/1492748/


All Articles