__ptr32 和 __ptr64 有什么意义? [英] What's the point of __ptr32 and __ptr64?

查看:91
本文介绍了__ptr32 和 __ptr64 有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇 MSDN 文章中所述,微软有这两种类型的注解来声明不同架构上的原生指针.但是,在第二行:

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

在 32 位系统上,用 __ptr64 声明的指针被截断为 32 位指针.在 64 位系统上,使用 __ptr32 声明的指针会被强制转换为 64 位指针.

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 coerced to a 64-bit pointer.

这听起来好像声明无关紧要;如果架构将 __ptrXX 的声明覆盖为默认值,那么首先标记 __ptrXX 有什么意义?

This sounds to me like the declaration doesn't matter; if the architecture overrides the declaration of __ptrXX to be the default anyways, what's the point of marking __ptrXX in the first place?

我看到 这个答案 说它是用于互操作的,但是如果声明基本上如上所述被覆盖,如何对互操作有帮助吗?

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

推荐答案

声明和分配 32 位指针与实际使用它之间存在很大差异.换句话说,取消引用指针.如果您在 64 位进程中执行此操作,则别无选择,只能将其符号扩展为 64 位指针.这就是胁迫"的意思.这可能意外地起作用,但您必须非常幸运.尝试是没有意义的.

There's a big difference between declaring and assigning a 32-bit pointer and actually using it. In other words, dereferencing the pointer. If you do that in a 64-bit process then there is no other option but to sign-extend it to a 64-bit pointer. Which is what "coerced" means. That may work by accident, but you'd have to be pretty lucky. It just doesn't make sense to try.

声明 __ptr32 的要点如该链接答案中所述,仅当您与 32 位进程互操作时才有意义.其中使用 32 位指针.这并不常见.

The point of declaring a __ptr32 is as described in that linked answer, it only makes sense when you interop with a 32-bit process. Which uses 32-bit pointers. It is not common.

这篇关于__ptr32 和 __ptr64 有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆