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

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. This 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.
In this 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 */ }
Writing Variable and Extensible Functions 147