C/C++ Programmer's Guide (G06.25+)

System-Level Programming
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
9-5
Writing Variable and Extensible Functions
instead of variable in native C programs. The following discussion about variable and
extensible functions applies only to TNS C and C++, not to native mode.
Declaring Variable Functions
The variable attribute directs the compiler to treat all parameters of a function as
though they are optional, even if some are required by your code. If you add
parameters to a variable function declaration, all procedures that call it must be
recompiled. The following example declares a variable function:
foo(int i, int j, int k);
#pragma function foo (variable)
{ ... /* foo declaration */ }
Specify the FUNCTION pragma at function declaration, not at function definition.
When you call a variable function, the compiler allocates space in the parameter area
for all the parameters. The compiler also generates a parameter mask, which indicates
which parameters are actually passed. You use the _arg_present() built-in operator
to test for the presence of actual parameters.
Declaring Extensible Functions
The extensible attribute enables you to add new parameters to a function
declaration without recompiling its callers. The compiler treats all parameters of a
function as though they are optional, even if some are required by your code. The
following example declares an extensible function:
foo(int i, int j, int k);
#pragma function foo (extensible)
{ ... /* foo declaration */ }
Specify the FUNCTION pragma at function declaration, not at function definition.
When you call an extensible function, the compiler allocates space in the parameter
area for all the parameters. The compiler also generates a parameter mask, which
indicates which parameters are actually passed. You use the _arg_present() built-
in operator to test for the presence of actual parameters.
Checking for Actual Parameters With _arg_present()
Each variable and extensible function must check for the presence or absence of
actual parameters that are required by the function’s code. The function can use the
_arg_present() operator to check for required or optional parameters. The operator
_arg_present() returns a zero if the parameter is absent; it returns a nonzero int
value if the parameter is present. The operand to _arg_present() must be a valid
formal parameter. The _arg_present() operator is a built-in operator; a header file
is not necessary.