[comp.lang.c] calling one varargs routine from another

chris@mimsy.umd.edu (Chris Torek) (10/28/89)

[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