home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0415.CPP
- #include <iostream.h>
- #include <stdarg.h> // defines va_start, va_end, and va_end
-
- void f(int a, int num_args,...) {
- va_list arg_pointer; // pointer to the list of arguments
- va_start(arg_pointer, num_args);
- // va_start makes its first argument
- // point to the unspecified arguments
- cout << "Here is argument a: " << a << endl;
- for ( int i = 0; i < num_args; i++) {
- cout << "Here is the unspecified argument " << i + 1;
- cout << ": " << va_arg(arg_pointer, int) << endl;
- // va_arg takes a pointer to unspecified arguments and a
- // type name as arguments. It returns an unspecified
- // argument of the types.
- }
- va_end(arg_pointer);
- }
-
- void main() {
- int a = 0;
- int b = 1;
- int c = 2;
- f(a, 0); // the second argument of f() is the number of
- f(a, 1, b); // unspecified arguments that are being passed.
- f(a, 2, b, c);
- }
-