Next: , Previous: , Up: Functions   [Index]


9.3 Variadic Functions

The variadic functions allow extra arguments of unspecified number and type after the ordinary arguments.

The extra arguments may be passed by the aime interpreter by reference if the pass by reference is preferred. Unlike for ordinary, non variadic function arguments, the pass by reference is for variadic arguments a mere preference indication and the variadic arguments may still be passed by value if the pass by reference is not possible.

The syntax indicating a function variadic character is the ‘...’ literal ending its arguments list definition. The pass by reference preference is indicated by a ‘&’ literal sign preceding the ‘...’ indication.

void
variadic_1(integer a, ...)
{
}

The function ‘variadic_1’ may be called with any number of arguments, save 0 and as long as the first is of the ‘integer’ type or convertible to it.

    variadic_1(3);
    variadic_1(2.0, 0, 1, 2, 3, 4, 5, 6, 7);
    variadic_1(3z, "variadic", l_effect(""));
    variadic_1(min(0, 1), variadic_1);
void
variadic_2(text b, real c, &...)
{
}

The function ‘variadic_2’ may be called with at least two arguments. The variadic arguments are passed by reference when possible, i.e. when they are read write variables.

    cardinal a;
    list l;

    variadic_2("v", 3);
    variadic_2("x", 2, a);
    variadic_2("z", 1, a, 0, l, 1048576);
integer
variadic_3(...)
{
    return count();
}

The function ‘variadic_3’ may be called with any number of arguments, a number that the function will return.