calling one varargs routine from another (how?!)

Chris Torek chris at mimsy.umd.edu
Sat Oct 28 14:49:06 AEST 1989


[followups redirected to comp.lang.c]

In article <21293 at adm.BRL.MIL> mark at 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 at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list