varargs functions: calling and prototyping
Dave Eisen
dkeisen at Gang-of-Four.Stanford.EDU
Fri Jul 27 02:46:09 AEST 1990
In article <1990Jul25.195944.9238 at DRD.Com> mark at drd.Com (Mark Lawrence) writes:
>
>I've got a function whose first three arguments should always be provided
>but the rest of the arguments will be handed to vsprintf for formatting.
>
>The function itself looks like:
>
[The K&R version of the function omitted for brevity]
#include <stdio.h>
#include <stdarg.h> /* varags is used in the K&R world, it doesn't work with
prototypes */
#include <alarms.h> /* which includes a function prototype for this func */
#define AlarmBufSz 1024
static char buf[AlarmBufSz];
/* The definition of the function matches the prototype given in alarm.h */
/* This prototype is */
/* void ReportAlarm (char *source, AlarmType alarm, char *fmt, ...); */
/*VARARGS3*/
void
ReportAlarm(char *source, AlarmType alarm, char *fmt, ...)
{
va_list args;
va_start(args, format); /* va_start now takes the last required function
parameter as its second argumnet. */
(void) vsprintf(buf, fmt, args);
va_end(args);
/* Other stuff ... */
}
--
Dave Eisen Home: (415) 323-9757
dkeisen at Gang-of-Four.Stanford.EDU Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043
More information about the Comp.lang.c
mailing list