C/C++ Programmer's Guide (G06.25+)
System-Level Programming
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
9-2
Passing Pointers to Constants Between Code
Spaces
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 blocks. Without relocatable data blocks, static data is not
allowed. Thus, the compiler allocates static data items such as constants in the user
code space instead of the user or system data spaces.)
To pass pointers to such constants in TNS C and C++ programs, you must use the
CSADDR pragma. (Native C programs do not require the CSADDR pragma.) The
CSADDR pragma directs the compiler to allocate sufficient space on the stack for each
code space data object pointed to by a function argument. It generates move
instructions to copy each data object to the corresponding implicit stack address,
based on information from previous data declarations. The new stack address, instead
of the code space address, is then passed as the function argument.
CRE library functions No Yes No
Constants allocated in code
space
No ** Yes Yes
Constants allocated in data
space
Yes No No
Table 9-1. Code Spaces and the Availability of Run-Time Library and Language
Features (page2of2)
Feature System Code User Library System Library
* 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.