Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!samsung!uunet!apctrc!drd!mark From: mark@DRD.Com (Mark Lawrence) Newsgroups: comp.lang.c Subject: varargs functions: calling and prototyping Summary: how to do it Keywords: varargs, prototypes Message-ID: <1990Jul25.195944.9238@DRD.Com> Date: 25 Jul 90 19:59:44 GMT Reply-To: mark@drd.Com (Mark Lawrence) Organization: DRD Corporation, Tulsa, OK Lines: 55 I'm using gcc 1.37 or so on a Sun SparcStation running 4.0.3. 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: #include #include #include /* which includes a function prototype for this func */ #define AlarmBufSz 1024 static char buf[AlarmBufSz]; /*VARARGS0*/ void ReportAlarm(va_alist) va_dcl { va_list args; AlarmType alarm; char *source; char *fmt; va_start(args); source = va_arg(args, char *); alarm = va_arg(args, AlarmType); fmt = va_arg(args, char *); (void) vsprintf(buf, fmt, args); va_end(args); /* and stuff ... */ } alarms.h looks like: #ifndef ALARMS_H #define ALARMS_H typedef enum { alNone, alFoo, alLastAlarm } AlarmType; /* void ReportAlarm(char * source, AlarmType alarm, char * fmt, ...) */ void ReportAlarm(); #endif /* ALARMS_H */ My questions are: 1) do I need to provide a terminating NULL when calling this function (I've seen it done int the Thom Plum notes on the Draft C Standard, but I've tried it in Saber without and it *seems* to work) 2) how do I prototype it? I tried the above commented out prototype and when compiling function, gcc gripes that it doesn't match its prototype and quits.