[vox-tech] macro arguments in C
Peter Jay Salzman
vox-tech@lists.lugod.org
Thu, 17 Oct 2002 13:43:12 -0700
i wrote a generalized "die" function:
void
die(int err, const char *file, const char *func, int line, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "\n\nFatal Error:\n");
fprintf(stderr, " file: %s, function: %s, line: %d\n", file, func, line);
fprintf(stderr, " strerror reports: %s\n", strerror(err));
vfprintf(stderr, " %s\n", args);
exit(0);
}
normally, i call this function as (for example):
die(errno, __FILE__, __FUNCTION__, __LINE__,
"you made boo-boo number %d.", boo-boo);
that's quite a mouthful. if possible, i'd like to use a macro to
shorten this to:
die("you made boo-boo number %d.", boo-boo);
the problem is the "..." in the die() declaration. i'm pretty sure that
macros can't take an arbitrary number of arguments. potentially, i'd
like to be able to call die as:
die("%c%c%c%c%c" 'o', 'o', 'p', 's', '!');
is there a way to shorten the call to die() and still transmit the
errno, file, function and line informatin?
pete
--
Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D