Date: Fri, 25 Feb 2000 19:17:08 -0800 From: Alfred Perlstein <bright@wintelcom.net> To: Marco Molteni <molter@csl.sri.com> Cc: freebsd-chat@FreeBSD.ORG Subject: Re: how to do this C preprocessor trick? Message-ID: <20000225191708.S21720@fw.wintelcom.net> In-Reply-To: <20000225182432.A5017@sofia.csl.sri.com>; from molter@csl.sri.com on Fri, Feb 25, 2000 at 06:24:32PM -0800 References: <20000225182432.A5017@sofia.csl.sri.com>
next in thread | previous in thread | raw e-mail | index | archive | help
* Marco Molteni <molter@csl.sri.com> [000225 18:54] wrote: > Hi all, > > I have a function that takes a variable number of arguments: > > void d_printf(const char *format, ...) > > I would like to make it print automatically the function name > from which it is called, eg instead of doing > > f() { d_printf("f: blabla", x, y, z); } > > doing simply > > f() { d_printf("blabla", x, y, z); } > > To do that, I though of wrapping d_printf() around a macro like > > #define dprintf(x) d_printf(__FUNCTION__, x) > > but whatever combination I use (also with #), the thing is not going to work: > > main.c:231: macro `d_printf' used with too many (4) args > > Is it possible to trick the C preprocessor to do what I want? It's kinda ugly but: #define panic(A) \ do { \ panic_set_location(__FILE__, __LINE__); \ panic_print_and_die A ; \ } while (0) you'll need to use your macro like this: panic(("foo! %s", msg)); there is a way to use varargs macros, but i don't think it's portable. good luck, -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000225191708.S21720>