OS/2 Version 2.0 allows applications and resources from both 16-bit and 32-bit environments to coexist and communicate. A 32-bit application may make function calls to 16-bit code, and 16-bit and 32-bit window procedures may pass messages between one another.
Conversion between the 16:16 and 0:32 addressing schemes is achieved using thunks, which implement an algorithm known as the Compatibility Region Mapping Algorithm. The IBM C Set/2 compiler provides transparent thunking for most function calls and parameters, using the #pragma linkage directive in conjunction with the _Seg16 keyword.
For threads that will make calls to 16-bit code, the stack must also be aligned on a 64KB segment boundary, to avoid possible problems with stack overflow in the 16-bit code. Again, the IBM C Set/2 compiler facilitates this alignment through use of the #pragma stack16 directive, which causes the thread's stack to be automatically aligned on a 64KB boundary.
Thunking becomes slightly more complex when communicating between 16-bit and 32-bit window procedures, since pointers passed in message parameters must be thunked. While Presentation Manager provides transparent thunking for all system-defined message classes, application-defined messages must be thunked explicitly by the application.
Presentation Manager provides some assistance to the application developer by allowing thunk procedures to be registered for a window. Presentation Manager automatically invokes the thunk procedure whenever a message to passed to that window from a window of another memory model.
The ability to mix 16-bit and 32-bit code in the same application provides considerable flexibility and protects investment in existing application functions and resources. This in turn eases the task of migrating the organizational development environment from the 16-bit to the 32-bit environment, since the transition need not be accomplished in a single step.