From owner-freebsd-chat Fri Feb 25 18:47:31 2000 Delivered-To: freebsd-chat@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 6654037BA8E for ; Fri, 25 Feb 2000 18:47:29 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) id TAA25601; Fri, 25 Feb 2000 19:17:08 -0800 (PST) Date: Fri, 25 Feb 2000 19:17:08 -0800 From: Alfred Perlstein To: Marco Molteni Cc: freebsd-chat@FreeBSD.ORG Subject: Re: how to do this C preprocessor trick? Message-ID: <20000225191708.S21720@fw.wintelcom.net> References: <20000225182432.A5017@sofia.csl.sri.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <20000225182432.A5017@sofia.csl.sri.com>; from molter@csl.sri.com on Fri, Feb 25, 2000 at 06:24:32PM -0800 Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org * Marco Molteni [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