calling one varargs routine from another (how?!)
Mark Valentine
mark at spider.co.uk
Sat Oct 28 03:56:13 AEST 1989
[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, ...)
? For traditional C, my best guess would be something like
#include <varargs.h>
void
fatal(va_alist)
va_dcl
{
error(va_alist);
exit(1);
}
(which actually worked for my test prog on a MIPS box, but not on a VAX).
For ANSI C, the nearest I can get to expressing what I want is
#include <stdarg.h>
void
fatal(char *message, ...)
{
va_list args;
va_start(args, message);
error(message, args);
va_end(args);
exit(1);
}
which doesn't work on either the MIPS or VAX! My test was
main()
{
fatal("%d... %d... %d... bye!\n", 3, 2, 1);
}
I feel I'm missing something, but... It would niggle me to expand a
six-line error routine in each of a handful of wrappers! On the other
hand I guess if this were possible we wouldn't have v*printf().
#if 0
A:
#endif
Mark.
--
Mark Valentine, Spider Systems <mark at spider.co.uk> /\oo/\
More information about the Comp.unix.wizards
mailing list