Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)
Figure 3 Mixed-Module Programming Using the c89 Utility
You should always include all relevant headers in the source modules to ensure function references
are resolved to the proper variant. Linking should be deferred until all object modules are created.
In the OSS environment, linking can be initiated automatically for you by the c89 or the c99 utility,
as discussed in Chapter 2 (page 31).
A mixed-module program enables Guardian C functions to access Guardian objects from an OSS
process and OSS functions to access OSS objects from a Guardian process. You should use OSS
C functions wherever possible to manipulate Guardian objects. For example, if you want to open
a Guardian file and do not need to access any of the attributes that Guardian files have and OSS
files do not, use the OSS open() function. However, you can use a Guardian C function when
you cannot accomplish a task with OSS functions.
Many Guardian C library functions can be called from OSS programs. However, they can be
called only from modules compiled for the Guardian environment. In this case, you compile the
Guardian and OSS modules separately and link them together. Use the SYSTYPE pragma to direct
the compiler to generate code appropriate for each environment. Specify SYSTYPE OSS for OSS
modules and SYSTYPE GUARDIAN for Guardian modules. Using mixed-module programming
should be minimized because of the knowledge required to keep code easier to maintain.
NOTE: You must compile Guardian and OSS modules separately (on the command line, not in
source code). The c89 and c99 utilities cannot compile two modules with different SYSTYPE
values.
The SYSTYPE pragma also defines the appropriate feature test macros for each environment.
Feature test macros and pragmas are discussed more in “OSS C Programming Considerations”
(page 115). More information about mixed-module programming can be found in the C/C++
Programmer’s Guide.
Design Considerations and Steps
When designing mixed-module programs, the first task is to decide on whether your program will
run as an OSS process or a Guardian process. Guardian objects are manipulated from the Guardian
module and OSS objects are manipulated from the OSS module. If the majority of a program’s
code uses the resources of and manipulates objects in the Guardian environment, consider writing
the program as a Guardian process. Likewise, if the majority of a program’s code uses the resources
of and manipulates objects in the OSS environment, consider writing the program as an OSS
process. Other factors, such as the availability of resources and services unique to each environment,
can also influence your decision.
Mixed-Module Programming 83