Re: how could I write this cpp macro



Ben Pfaff wrote:
Bilgehan.Balban@xxxxxxxxx writes:

I'm trying to convert this:

printf("format str %s, %s", "str arg 1", "str arg 2 etc.");

to this:

printf("%s: " "format str %s, %s", __FUNCTION__, "str arg 1", "str arg2
etc.");

It's ghastly, but
#define pdebug printf("%s:", __FUNCTION__), printf
might do what you want.

There are probably C99-specific solutions, and definitely
GCC-specific solutions, as well.

I think Ben's solution or a variant of it may be what you want. Your
method of concatenating string literals precludes people from using a
variable as the format string, not ideal if this is to be widely used.
e.g.

const char *format = "%s %d %s";
pdebug(format, foo, bar, bas);

would break.

-David

.