__ptr32、__ptr64

Microsoft 特定的

__ptr32 表示 32 位系統上的原生指標,而 __ptr64 表示 64 位系統上的原生指標。

下列範例將示範如何宣告每一個這些類型的指標:

int * __ptr32 p32;
int * __ptr64 p64;

在 32 位系統上,以 __ptr64 宣告的指標會截斷為 32 位指標。 在 64 位系統上,使用 __ptr32 宣告的指標會強制轉換為 64 位指標。

注意

您無法在使用 /clr:pure 進行編譯時使用 __ptr32__ptr64 。 否則,會產生編譯器錯誤 C2472。 Visual Studio 2015 中已淘汰 /clr:pure /clr:safe 編譯器選項,且 Visual Studio 2017 不支援。

為了與舊版相容, 除非指定編譯器選項 /Za(停用語言延伸模組), 否則_ptr32 和_ptr64 是 和 __ptr64__ptr32 同義字。

範例

下列範例示範如何使用 和 __ptr64 關鍵字來宣告和配置指標 __ptr32

#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;
}
32
64

END Microsoft 特定的

另請參閱

內建類型