home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
c_all592.arj
/
TI733.ASC
< prev
next >
Wrap
Text File
|
1992-02-25
|
1KB
|
67 lines
PRODUCT : Borland C++ NUMBER : 733
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 PAGE : 1/1
TITLE : How to Use Variable Arguments
/*************************************************************
Example code for using a variable number of arguments.
There is only one guaranteed way of accessing arguments passed
using the ... mechanism. The standard header file <stdarg.h> as
specified for ANSI C will provide declarations that can be used
by a function that does not know the number or types of its
arguments when it is compiled.
*************************************************************/
#include <stdarg.h>
void real_handler(const char*, va_list);
void my_error_handler(const char* format ...)
{
// ...
va_list ap;
va_start(ap,format);
real_handler(format,ap); /* get arguments */
va_end(ap);
exit(99);
}
void real_handler(const char* format, va_list ap)
{
// assume that 'format' tells us that
// three arguments, a char*, an int, and a double,
// are passed - in that order - by the va_list 'ap'
char* p = va_arg(ap,char*);
int i = va_arg(ap,int);
double d = va_arg(ap,double);
}