Clib.va_arg()
syntax: |
Clib.va_arg([valist[, offset]) Clib.va_arg(offset) Clib.va_arg() |
where: |
valist - a variable list of arguments passed to a function.
offset - index of a particular argument.
|
return: |
value - parameter being retrieved. If no parameters, the number of parameters.
|
description: |
The method Clib.va_arg() provides an alternate way to retrieve a function's parameters. It's most often used when the number of parameters passed to the function is not constant. This method covers the same territory as the Function property arguments[] and is provided for those who prefer C functions for handling variable arguments.
When called with no parameters, it returns the number of parameters passed to the current function. If an offset is supplied, it returns the input variable at index: offset. Clib.va_arg(0) is the first parameter passed, Clib.va_arg(1) the second, etc. It is a fatal error to retrieve an argument offset beyond the number of parameters in the function or the valist.
The valist form, with an optional offset, uses a valist variable that has been previously initialized with Clib.va_start(). Each call to Clib.va_arg(valist) returns the next parameter passed to a function. If an offset is passed in the variable at that offset from the original starting place of the valist will be returned.
|
see: |
Clib.va_start(), Clib.va_end(), Clib.vfprintf(), Clib.vfscanf(), Clib.vprintf(), Clib.vscanf(), Clib.vsprintf(), Clib.vsscanf()
|
example: |
// The following script:
function main() { lips(0, 1, 2, 3, 4) }
lips() { Clib.va_start(valist) Clib.printf("va_arg(0) = %d\n", va_arg(0)); Clib.printf("va_arg(1) = %d\n", va_arg(1)); Clib.printf("va_arg(valist) = %d\n", va_arg(valist)); Clib.printf("va_arg(valist, 2) = %d\n", va_arg(valist, 2)); Clib.printf("va_arg(valist, 2) = %d\n", va_arg(valist, 2)); Clib.printf("va_arg(valist) = %d\n", va_arg(valist)); Clib.getch() }
// produces the following output: // va_arg(0) = 0 // va_arg(1) = 1 // va_arg(valist) = 0 // va_arg(valist, 2) = 3 // va_arg(valist, 2) = 3 // va_arg(valist) = 1 |