HP C A.06.05 Reference Manual
HP C/HP-UX Implementation Topics
The varargs Macros
Chapter 10 255
default: printf ("bad argument type %d\n", ptype);
ptype = END_OF_LIST; /* to break loop */
break;
} /* switch */
} while (ptype != END_OF_LIST);
}
/* Clean up */
va_end (ap);
}
main()
{
int x = 99;
foo (1, NO_VAR_LIST);
foo (2, VAR_LIST_PRESENT, DOUB, 3.0, PINT, &x, END_OF_LIST);
}
C9X standard macros
The C9X standard-compliant version of "variadic" or variable argument (varargs) macro
notation has been added to the HP ANSI C compiler. The notation for C9X standard and for
the GNU version of varargs is very similar.
If you have coded your macros to the GNU standards, you can expect GNU-style behavior
using the HP ANSI C compiler. If you have coded your macros to C9X standards, you can
expect C9X-style behavior.
Usage Differences
In the HP ANSI C compiler, an ellipsis (...) at the end of the parameter list in a macro
definition indicates that the macro takes a variable number of arguments, or is variadic in
nature. The ellipsis should be the final parameter in C9X style and should immediately follow
the final parameter in GNU style.
The last parameter in a variable argument definition is referred to as the variable argument
parameter. In GNU terminology, this is known as the rest parameter. In a C9X style
definition, the variable argument parameter does not explicitly appear in the parameter list
but is referred to by the identifier __VA_ARGS__ in its replacement text.