__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 特定的
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應