The __ptr32 type qualifier

The keyword __ptr32 is a qualifier that can be applied to a pointer type to constrain its size to 32 bits. This language extension is provided to facilitate porting structures with pointer members from 31- to 64-bit mode. The qualifier is accepted and ignored in 31-bit mode.

The size of a pointer type doubles to 64 bits in 64-bit mode. Doubling the size of a pointer changes the layout of a structure that contains pointer members. If the object referenced by a pointer member resides within a 31-bit addressing space, constraining the pointer to 32 bits can reduce some of the unexpected effects of moving to 64-bit mode.

The __ptr32 keyword can appear in the declarator part of a pointer declaration, wherever a cv-qualifier can be used. For example,
      int * __ptr32 p;
declares p to be a 32-bit pointer to int.
      int * __ptr32 *q;
declares q to be a 64-bit pointer to a 32-bit pointer to int.
      int * __ptr32 const r;
declares r to be a const 32-bit pointer.

Pointers with external linkage must be __ptr32-qualified consistently across all compilation units. If a pointer is declared 31-bit in one compilation unit and 64-bit in another, the behavior is undefined.

Assignment of 32-bit and 64-bit pointers to each other is permitted. The compiler generates an implicit conversion or truncates without emitting a diagnostic.

Note: The terms 31-bit mode and 32-bit mode are used interchangeably when there is no ambiguity. The term 32-bit mode is commonly used in the industry to refer to a class of machines, to which z/OS® in 31-bit mode belongs. Strictly speaking, 31-bit mode refers to the addressing mode of the architecture, and 32 bits refers to the size of the pointer type. In z/OS 31-bit addressing mode, the size of a pointer is four bytes. However, the high-order bit is reserved for system use, and is not used to form the address. The addressing range in this mode is therefore 2 gigabytes. In 64-bit mode, the size of a pointer is eight bytes, and all 64 bits participate in addressing. When a __ptr32 pointer is dereferenced, a 64-bit address is formed by filling the 33 missing high-order bits with zeros. The program using that address should make sure it is valid within the address space of the application.