C/C++ Programmer's Guide (G06.25+)
System-Level Programming
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
9-4
Writing Variable and Extensible Functions
for (p = name; i <= LAST_NAME ; i++, p = &name[i])
if (!strcmp(p, "kevin"))
return TRUE;
return FALSE;
}
Note the inclusion of pragma inline in the preceding compilation unit. Because the
passing of pointers to code space is hazardous for the run-time function call of
strcmp, generation of inline code is safer.
You can also place constants in the code space with the _cspace type qualifier.
However, the _cspace type qualifier is effective only on the specified data constant.
Other constants in the function without the type qualifier are still allocated in the static
data space. The use of the _cspace qualifier under the ENV LIBRARY or ENV
LIBSPACE pragmas is redundant for object definitions with the type qualifier const,
except for pointers. For example, you must specify _cspace in the following
declaration to store the object in the code space, regardless of specified ENV pragma:
#pragma env libspace
const char * lvar = "x"; /* Stored in data space */
const _cspace char * hvar = "y"; /* Stored in code space */
The following example declares the arr constant array to be located in the current
code space:
_cspace const char arr[] = "ABCD";
The following example declares a pointer data type to point to a constant item located
in the code space:
extern _cspace const int * ptr;
If you apply the & operator to a constant stored in the code space, the result is a 32-bit
extended pointer.
Writing Variable and Extensible Functions
Variable and extensible functions are HP extensions to the ISO/ANSI C language
standard. This subsection describes how to use variable and extensible functions,
including:
•
Declaring variable functions with the variable attribute
•
Declaring extensible functions with the extensible attribute
•
Checking for actual parameters with the _arg_present() operator
•
Omitting parameters on calls to variable and extensible functions
•
Converting variable functions to extensible functions
For a complete syntax description for writing variable and extensible function
declarations, refer to the description of pragma FUNCTION on page 13-36.
For native C, variable and extensible functions are treated the same. The semantics
used are those for extensible functions. Therefore, declare procedures extensible