__ptr32, __ptr64

Microsoft 专用

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

下面的示例演示如何声明这些指针类型的每种:

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++)