Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Feb 2000 18:24:32 -0800
From:      Marco Molteni <molter@csl.sri.com>
To:        freebsd-chat@freebsd.org
Subject:   how to do this C preprocessor trick?
Message-ID:  <20000225182432.A5017@sofia.csl.sri.com>

next in thread | raw e-mail | index | archive | help
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?

Thanks
Marco
-- 
Marco Molteni "rough consensus and running code"
SRI International, System Design Laboratory


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?20000225182432.A5017>