C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

9 System-Level Programming
System-level programming refers to the ability to write TNS C and C++ functions that reside in
system code, system library, or user library. It also refers to native C and C++ functions that reside
in user library. Customer-written native C and C++ functions cannot reside in system code or system
library. System-level programming is available only in the Guardian environment.
Specifying a Code Space
A code space is a part of virtual memory that is reserved for user code, user library code, system
code, and system library code. Depending upon the code space, the C compiler generates different
code and places different restrictions on your code. Use the ENV pragma to specify the code space.
To compile functions to run in system code, specify ENV EMBEDDED. To compile functions to run
in system library, specify ENV LIBSPACE. To compile functions to run in user library, specify ENV
LIBRARY. For more details, see the description of the pragma ENV (page 183).
For each code space, there are restrictions on the run-time library and language features that can
use be used. Table 24 summarizes the availability of run-time library and language features for
each code space.
Table 24 Code Spaces and the Availability of Run-Time Library and Language Features
System LibraryUser LibrarySystem CodeFeature
NoYes *NoC I/O functions
NoYesNoMemory allocation functions
NoNoNoMain routine
NoNoYesRelocatable data blocks
NoYesNoFunctions that set errno
NoYesNoCRE library functions
YesYesNo **Constants allocated in code
space
NoNoYesConstants allocated in data
space
* TNS C and C++ programs can use functions in a user library if direct access to relocatable data blocks is not needed
for the operations. Native C and C++ programs in a user library can use any C library function. **The _cspace
type qualifier lets you allocate constants in the code space.
Because of these restrictions on resources, functions that run in user library, system library, or system
code cannot use the complete C run-time library. For example, functions that are dependent upon
their execution context because their semantics require references to external data can run only in
user code or system code.
Passing Pointers to Constants Between Code Spaces
A code space is a part of virtual memory that is reserved for user code, user library code, system
code, and system library code. A data space is an part of virtual memory that is reserved for user
data and system data. For functions that reside in the user code space, the compiler places variables
of type const, constant values on the right-hand side of initialization statements, and strings in
the user data space.
For functions that reside in the user library space or system library space, the compiler places
variables of type const, constant values on the right-hand side of initialization statements, and
strings in the user code space. (User library and system library do not allow relocatable data
144 System-Level Programming