www.delorie.com/gnu/docs/glibc/libc_677.html   search  
 
Buy the book!


The GNU C Library

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A.2.3.1 Old-Style Variadic Functions

Before ISO C, programmers used a slightly different facility for writing variadic functions. The GNU C compiler still supports it; currently, it is more portable than the ISO C facility, since support for ISO C is still not universal. The header file which defines the old-fashioned variadic facility is called `varargs.h'.

Using `varargs.h' is almost the same as using `stdarg.h'. There is no difference in how you call a variadic function; see A.2.2.4 Calling Variadic Functions. The only difference is in how you define them. First of all, you must use old-style non-prototype syntax, like this:

 
tree
build (va_alist)
     va_dcl
{

Secondly, you must give va_start only one argument, like this:

 
  va_list p;
  va_start (p);

These are the special macros used for defining old-style variadic functions:

Macro: va_alist
This macro stands for the argument name list required in a variadic function.

Macro: va_dcl
This macro declares the implicit argument or arguments for a variadic function.

Macro: void va_start (va_list ap)
This macro, as defined in `varargs.h', initializes the argument pointer variable ap to point to the first argument of the current function.

The other argument macros, va_arg and va_end, are the same in `varargs.h' as in `stdarg.h'; see A.2.2.5 Argument Access Macros, for details.

It does not work to include both `varargs.h' and `stdarg.h' in the same compilation; they define va_start in conflicting ways.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003