nargs(3C)
_________________________________________________________________
nargs $builtin function
Return the number of arguments for the executing routine.
_________________________________________________________________
Calling Sequence
int nargs(), argnum;
argnum = nargs();
(or)
$builtin int nargs();
int argnum;
argnum = nargs();
Description
Use the nargs function to find the number of arguments for the
executing routine. The first version above uses a function call.
The second might generate smaller or faster code, but may not run
under other C compilers.
NOTE: The nargs function counts floating-point arguments as two
passed values; therefore, it could miscount.
Returns
The nargs function returns the number of arguments for the
executing routine.
Related Functions
See also the argc argument in the description of the main
function.
Example
/* Program test for the nargs() function */
int i = 1, argnum;
main(argc, argv)
int argc;
char *argv[];
{
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
nargs(3C)
while (i < argc) {
subord(argv[i]);
i++;
}
printf("Number of arguments to main = %d\n",
argnum = nargs());
printf("Last argument to main is %s.\n", argv[argc-1]);
}
subord(a)
char a[];
{
printf("Argument to subord on call %d is %s.\n", i, a);
printf("Number of arguments to subord = %d\n\n",
argnum = nargs());
}
A call to the program test with the arguments alpha, beta, and
gamma generates the output
Argument to subord on call 1 is alpha.
Number of arguments to subord = 1
Argument to subord on call 2 is beta.
Number of arguments to subord = 1
Argument to subord on call 3 is gamma.
Number of arguments to subord = 1
Number of arguments to main = 3
Last argument to main is gamma.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)