C and C++ In the
C and
C++ programming languages, an ellipsis is used to represent a
variable number of parameters to a
function. These C-style variadic parameters are type-unsafe, not capturing any information about types of the passed variadic arguments, and must be stored in a va_list type and read using macros like va_start(), va_arg(), and va_end(). For example: int printf(const char* fmt, ...); The above function in C could then be called with different types and numbers of parameters such as: // prints "numbers 5 10 15" printf("numbers %i %i %i", 5, 10, 15); // prints "input string another string, 0.5" printf("input string %s, %f", "another string", 0.5);
C99 introduced macros with a
variable number of arguments.
C++11 included the new variadic macro features introduced in the C99 preprocessor, and also introduced templates with a variable number of arguments, called
variadic templates, which are how type-safe variadic parameters are implemented in C++. using std::string_view; template void myPrintf(string_view fmt, Args... parameters);
Java As of version 1.5,
Java has adopted this "varargs" functionality. For example: public int func(int num, String... names); This actually converts to String[] names, but is not required to be wrapped in an array.
PHP PHP 5.6 supports use of ellipsis to define an explicitly
variadic function, where ... before an argument in a function definition means that arguments from that point on will be collected into an array. For example: function variadic_function($a, $b, ...$other) { return $other; } var_dump(variadic_function(1, 2, 3, 4, 5)); Produces this output: array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) } == Scheme ==