Chapter 25: Variable-Length Argument Lists

All of the functions we've written so far have taken a fixed number of arguments, and we've been careful to call the functions always passing them the correct number of arguments, and we've been tending to use explicit function prototype declarations so that the compiler can verify that we call functions with the correct number of arguments. But what about printf? Sometimes we call it with one argument, but often we pass it additional arguments. Why doesn't the compiler complain? How can printf access the extra arguments we pass to it, when it can't know how many of them there will be or what types they will have, such that it can't possibly declare conventional function parameters for them?

In this chapter we'll discuss the variable-length argument lists (often discussed under the shorthand term ``varargs'') which allow functions such as printf to be written.

25.1 Declaring ``varargs'' Functions

25.2 Writing a ``varargs'' Function

25.3 Special Issues with Varargs Functions

Read sequentially: prev next up top

This page by Steve Summit // Copyright 1996-1999 // mail feedback