cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdarg (stdarg.h) : va_end
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdarg (stdarg.h)
macros:
· va_arg
· va_end
· va_start
types::
· va_list

-

va_end macro
void va_end ( va_list ap );
<cstdarg>

End using variable argument list

Performs the appropiate actions to facilitate a normal return by a function that has used the va_list object ap to retrieve its additional arguments.

This macro should be executed before the function returns whenever va_start has been previously used in that function.

Parameters

ap
va_list object previously initialized by va_start in the same function.

Return Value

none

Example

/* va_arg example */
#include <stdio.h>
#include <stdarg.h>

void PrintLines ( char* first, ...)
{
  char* str;
  va_list vl;

  str=first;

  va_start(vl,first);

  do {
    printf ("%s\n",str);
    str=va_arg(vl,char*);
  } while (str!=NULL);

  va_end(vl);
}

int main ()
{
  PrintLines ("First","Second","Third","Fourth",NULL);
  return 0;
}

The PrintLines function takes a variable number or arguments. The first argument passed becomes parameter first, but the remaining are retrieved sequentially in the do-while loop using va_arg until a null pointer is retrieved as the next argument.

See also

va_start Initialize a variable argument list (macro)
va_arg Retrieve next argument (macro)
va_list Type to hold information about variable arguments (type)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us