__ptr32, __ptr64

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see __ptr32, __ptr64 on docs.microsoft.com.

__ptr32 represents a native pointer on a 32-bit system, while __ptr64 represents a native pointer on a 64-bit system.

The following example shows how to declare each of these pointer types:

int * __ptr32 p32;  
int * __ptr64 p64;  

On a 32-bit system, a pointer declared with __ptr64 is truncated to a 32-bit pointer. On a 64-bit system, a pointer declared with __ptr32 is coerced to a 64-bit pointer.

System_CAPS_ICON_note.jpg Note

You cannot use __ptr32 or __ptr64 when compiling with /clr:pure. Otherwise, Compiler Error C2472 will be generated.

The following example shows how to declare and allocate pointers with the __ptr32 and __ptr64 keywords.

#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  

Fundamental Types

Show: