Used in place of procedure parameter to pass a variable number of arguments, or as the upper bound in an array declaration to denote that the number of elements will be determined by the initializer.
Syntax
Description
The ellipsis (three dots,
...) is used in procedure declarations and definitions to indicate a variable argument list. A first argument must always be specified and the function must be called with the C calling convention
cdecl. In the procedure body,
va_first,
va_arg and
va_next are used to handle the variable arguments.
Only numeric types and pointers are supported as parameters.
Strings can be passed, in which case a
ZString Ptr to the string data is taken.
Using an ellipsis in place of the upper bound in an array declaration causes the upper bound to be set according to the data that appears in the
expression_list. When the ellipsis is used in this manner, an initializer must appear, and cannot be
Any.
Using an ellipsis behind the last parameter in a
#define or
#macro declaration allows to create a variadic macro. This means it is possible to pass any number of arguments to the
variadic_parameter, which can be used in the
body as if it was a normal macro parameter. The
variadic_parameter will expand to the full list of arguments passed to it, including commas, and can also be completely empty.
Example
Declare Function foo cdecl (x As Integer, ...) As Integer
Dim As Integer myarray(0 To ...) = {0, 1, 2, 3}
Print LBound(myarray), UBound(myarray) '' 0, 3
'' Using a variadic macro to wrap a variadic function
#include "crt.bi"
#define eprintf(Format, args...) fprintf(stderr, Format, args)
eprintf(!"Hello from printf: %i %s %i\n", 5, "test", 123)
'' LISP-like accessors allowing to modify comma-separated lists
#define car(a, b...) a
#define cdr(a, b...) b
Differences from QB
See also