Xref: utzoo comp.unix.wizards:18993 comp.lang.c:23421 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: calling one varargs routine from another (how?!) Message-ID: <20441@mimsy.umd.edu> Date: 28 Oct 89 04:49:06 GMT References: <21293@adm.BRL.MIL> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 48 [followups redirected to comp.lang.c] In article <21293@adm.BRL.MIL> mark@spider.co.uk (Mark Valentine) writes: >[If I had USENET postability this would be in comp.lang.c. But I don't think > it's entirely a waste of bandwidth here...] >Q: Is there a portable way, both in ANSI and traditional C, to call a > varargs function such as > void error(char *message, ...) > from another such as > void fatal(char *message, ...) No. However, it is easy to do without. Viz: void error(char *fmt, ...) { va_list ap; va_start(fmt, ap); verror(0, fmt, ap); va_end(ap); } void fatal(char *fmt, ...) { va_list ap; va_start(fmt, ap); verror(1, fmt, ap); va_end(ap); } void verror(int is_fatal, char *fmt, va_list ap) { static int errors; (void) vfprintf(stderr, fmt, ap); (void) putc('\n', stderr); if (++errors >= MAX_ERRORS) { (void) fprintf(stderr, "(that makes %d errors; please try again)\n", errors); is_fatal = 1; } if (is_fatal) { remove_temporary_files(); unlock_resources(); exit(EXIT_FAILURE); } } -- `They were supposed to be green.' In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris