__ptr32、__ptr64

Microsoft 专用

__ptr64 表示 32 位系统中的本机指针,而 __ptr32 表示 64 位系统中的本机指针。

以下示例演示如何声明所有这些指针类型:

int * __ptr32 p32;
int * __ptr64 p64;

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

备注

当使用 /clr:pure 进行编译时,不能使用 __ptr32 或 __ptr64。否则,将生成 Compiler Error C2472

示例

以下示例演示如何使用 __ptr32 和 __ptr64 关键字声明和分配指针。

#include <cstdlib>
#include <iostream>

int main()
{
    using namespace std;

    int * __ptr32 p32;
    int * __ptr64 p64;

    p32 = (int * __ptr32)malloc(4);
    *p32 = 32;
    cout << *p32 << endl;

    p64 = (int * __ptr64)malloc(4);
    *p64 = 64;
    cout << *p64 << endl;
}
  

请参见

参考

基本类型 (C++)