Ellipsis and void

An ellipsis at the end of the parameter specifications is used to specify that a function has a variable number of parameters. The number of parameters is equal to, or greater than, the number of parameter specifications. At least one parameter declaration must come before the ellipsis.

      int f(int, ...);

C++ The comma before the ellipsis is optional. In addition, a parameter declaration is not required before the ellipsis.

C The comma before the ellipsis as well as a parameter declaration before the ellipsis are both required in C.

Parameter promotions are performed as needed, but no type checking is done on the variable arguments.

You can declare a function with no arguments in two ways:

      int f(void);
      int f();

C++An empty argument declaration list or the argument declaration list of (void) indicates a function that takes no arguments.

C An empty argument declaration list means that the function may take any number or type of parameters.

The type void cannot be used as an argument type, although types derived from void (such as pointers to void) can be used.

In the following example, the function f() takes one integer argument and returns no value, while g() expects no arguments and returns an integer.

      void f(int);
      int g(void);

Related References

IBM Copyright 2003