### Using _Far32_Pascal Function Pointers

IBM C and C++ Compilers provides special 48-bit function pointers so you can make indirect calls to 32-bit functions that use the _Far32 _Pascal convention. The _Far32 _Pascal pointers are required to build virtual device drivers and similar applications that run at ring 0. For example, you would use 48-bit pointers to allow your VDD to communicate with physical device drivers.

The _Far32 _Pascal pointers, like the _Far32 _Pascal calling convention, are only supported when the /Gr+ compiler option is specified.

The 48-bit pointer consists of 2 fields:

1. A 16-bit selector value which identifies the code segment.
2. A 32-bit offset value which identifies the function's location in the segment.

To declare a 48-bit pointer, use the _Far32 and _Pascal keywords in the pointer declaration. For example:

       void (* _Far32 _Pascal foo)(int);

declares foo to be a 48-bit pointer to a function with the _Far32 _Pascal convention that takes an integer argument and does not return a value.

The only operations that can be performed on or with a _Far32 _Pascal pointer are:

- Calling the function.
- Assigning the pointer, which includes casting it to a 32-bit function pointer or to an integer or unsigned type.
- Initializing the pointer, either statically or at run-time, with the address of a _Far32 _Pascal or 32-bit function, or with an integer or unsigned value.
- Comparing two pointers for equality or inequality. Like all function pointers, 48-bit pointers cannot be compared using relational operators.
- Passing the pointer as a parameter or returning it from a function. 48-bit pointers are passed in the same way as aggregates. The offset portion is returned in EAX and the selector portion in DX.

If you assign an integer or unsigned value to a 48-bit pointer, the selector field of the pointer is set to the default CODE32 segment, and the offset field is initialized to the integer value being assigned. This type of assignment is not generally useful, because you cannot know where a function will reside in a code segment, and because if your code segment is CODE32, a 32-bit function pointer is sufficient.

Note: _Far32 _Pascal pointers cannot be directly converted to _Far16 pointers.

Developing Virtual Device Drivers in OS/2
Calling Between 32-bit and 16-bit Code

Keywords