POINTER_32 - 它是什么,为什么?
我刚刚接到将旧版应用程序从 32 位更新到 64 位的任务。在审查任务的范围时,我在包含外部(例如平台)标头之前立即发现了以下定义:
#define POINTER_32
我找不到使用此定义的内容或它具有什么效果,但它看起来像是那种将要使用的东西与我的任务直接相关!
它是做什么用的?它有什么用?立即删除它是否安全(我认为从长远来看有必要删除它)?
这是使用 MS VC++ 2008,即将是 2010 年。
I have just been given the task of updating a legacy application from 32-bit to 64-bit. While reviewing the extent of the task, I discovered the following definition immediately before the inclusion of external (eg. platform) headers:
#define POINTER_32
I cannot find what uses this definition or what effect it has, but it looks like the kind of thing that will be directly relevant to my task!
What is it for? What uses it? Will it be safe to remove it immediately (I presume it will be necessary to remove it in the long run)?
This is using MS VC++ 2008, soon to be 2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个通常在 Windows SDK 头文件 BaseTsd.h 中声明的宏。在 32 位模式下编译时,它的定义如您所示。在 64 位模式下编译时,它被定义为
MSVC 编译器扩展,用于在 64 位代码模型中声明 32 位指针。 32 位代码还有 64 位风格:
如果您编写 64 位程序并且需要与另一个进程中 32 位代码使用的结构进行互操作,则可以使用它。例如:
This is a macro that's normally declared in a Windows SDK header, BaseTsd.h header file. When compiling in 32-bit mode, it is defined as you showed. When compiling in 64-bit mode it is defined as
which is an MSVC compiler extension to declare 32-bit pointers in a 64-bit code model. There's also a 64-bit flavor for 32-bit code:
You'd use it if you write a 64-bit program and need to interop with structures that are used by 32-bit code in another process. For example:
用于绕过警告C4244。在 32 位和 64 位模型中提供 32 位指针
Used to get around the Warning C4244 . Provides a 32-bit pointer in both 32-bit and 64-bit models
我的客人是,它最初是为 VLM 创建的 (超大内存) 在 Alpha AXP 中,因为 Windows NT for Alpha 是 第一个具有部分 64 位支持的 Windows。 操作系统仍然是32位 但它具有 VLM API,供应用程序在必要时分配大64位内存,因此必须有某种方法在同一程序中声明 32 位和 64 位指针
VLM 返回应用必须存储的
POINTER_64
。默认情况下使用POINTER_32
/__ptr32
,而POINTER_64
/__ptr64
将在 64 位处理代码中使用甚至仍然可以在 Windows 文档和与
POINTER_32
相关的头文件中看到 AXP 的一些遗迹__AXP64__
适用于 Alpha AXP。即使 Windows 不再在该平台上运行,您也可以在 Ntdef.h 和 Winnt.h 中找到许多对 Alpha AXP 的其他引用。因此,还有
POINTER_SIGNED
和POINTER_UNSIGNED
宏,用于指定如何将 32 位地址扩展为 64 位地址。它们将扩展为__sptr
和__uptr
另一种用法是在禁用
LARGEADDRESSAWARE
在 64 位应用程序中与 Linux 中的 x32 ABI 完全相同,其中
long
和指针是32位宽当设置
/LARGEADDRESSAWARE:NO 时
即使高 32 位没有有效值,指针的大小仍然是 64 位宽。因此,为了节省指针的内存,我们必须将它们声明为POINTER_32
请参阅如何在 Windows 上检测 X32?
My guest is that it was originally created for VLM (Very Large Memory) in Alpha AXP, because Windows NT for Alpha is the first Windows with some 64-bit support. The OS is still 32-bit but it has the VLM API for applications to allocate large 64-bit memory if necessary, hence there must be some way to declare both 32 and 64-bit pointers in the same program
VLM returns
POINTER_64
that the app has to store.POINTER_32
/__ptr32
are used by default, andPOINTER_64
/__ptr64
will be used in 64-bit handling codeYou can still even see some relics of AXP in Windows documentation and header files related to
POINTER_32
__AXP64__
is meant for Alpha AXP. You can also find lots of other references to Alpha AXP in Ntdef.h and Winnt.h even though Windows no longer runs on that platformBecause of this there are also
POINTER_SIGNED
andPOINTER_UNSIGNED
macros to specify how the 32-bit address is extended to the 64-bit one. They'll be expanded to__sptr
and__uptr
Another usage would be for 32-bit pointers when disabling
LARGEADDRESSAWARE
in a 64-bit applicationIt's exactly the same as x32 ABI in Linux where
long
and pointers are 32-bit wideWhen setting
/LARGEADDRESSAWARE:NO
the size of pointers are still 64-bit wide even though the high 32 bits has no significant values. Therefore to save memory for the pointer we must declare them asPOINTER_32
See How to detect X32 on Windows?