Path: utzoo!attcan!uunet!decwrl!shelby!neon!Gang-of-Four!dkeisen From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.lang.c Subject: Re: varargs functions: calling and prototyping Keywords: varargs, prototypes Message-ID: <1990Jul26.164609.5088@Neon.Stanford.EDU> Date: 26 Jul 90 16:46:09 GMT References: <1990Jul25.195944.9238@DRD.Com> Sender: news@Neon.Stanford.EDU (USENET News System) Organization: Sequoia Peripherals Lines: 42 In article <1990Jul25.195944.9238@DRD.Com> mark@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 #include /* varags is used in the K&R world, it doesn't work with prototypes */ #include /* 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@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043