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

System-Level Programming
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
9-6
Writing Variable and Extensible Functions
In the following example of a variable function, a default value is assigned if the first
argument is absent. It operates on the second argument if it is present.
void errmsg (int x, int p1, int p2);
#pragma function errmsg (variable)
/* function declaration */
_variable void errmsg (int x, int p1, int *p2)
/* function definition */
#define P1_DEFAULT_VALUE -1
{
if (!_arg_present(p1)) /* Valid, use default value */
{ p1 = P1_DEFAULT_VALUE; /* if p1 is absent */
...
}
if (_arg_present(p2)) /* Valid, use the passed value */
{ *p2 = 10; /* if p2 is present */
...
}
}
Omitting Parameters
When you call a variable or extensible function, you can omit parameters indicated as
being optional in the called function. To omit parameters, use a place-holding comma
for each omitted parameter up to the last specified parameter. Here is an example:
void someproc (int x, int length, int limit, int total);
#pragma function someproc (extensible)
{ ... /* function declaration */ }
{
/* Lots of code */
}
void anotherproc (int i);
{ int total;
total = 259;
/* Some code */
someproc (23,,,total);
/* Omit length and limit parameters */
}
Converting Variable Functions to Extensible Functions
You can convert a TNS C or C++ variable function into an extensible function. When
you do so, the compiler converts the _variable parameter mask into an
_extensible parameter mask. Converting a native C or C++ variable function into an