top/contents search

15. Variable-Length Argument Lists

15.1 I heard that you have to #include <stdio.h> before calling printf. Why?

15.2 How can %f be used for both float and double arguments in printf? Aren't they different types?

15.3 I had a frustrating problem which turned out to be caused by the line

	printf("%d", n);
where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this.

15.4 How can I write a function that takes a variable number of arguments?

15.5 How can I write a function that takes a format string and a variable number of arguments, like printf, and passes them to printf to do most of the work?

15.6 How can I write a function analogous to scanf, i.e. that accepts similar arguments, and calls scanf to do most of the work?

15.7 I have a pre-ANSI compiler, without <stdarg.h>. What can I do?

15.8 How can I discover how many arguments a function was actually called with?

15.9 My compiler isn't letting me declare a function

	int f(...)
	{
	}
i.e. accepting a variable number of arguments, but with no fixed arguments at all.

15.10 I have a varargs function which accepts a float parameter. Why isn't

va_arg(argp, float)
working?

15.11 I can't get va_arg to pull in an argument of type pointer-to-function.

15.12 How can I write a function which takes a variable number of arguments and passes them to some other function (which takes a variable number of arguments)?

15.13 How can I call a function with an argument list built up at run time?


top

contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North