Re: how could I write this cpp macro
- From: "L7" <jesse.r.brown@xxxxxxxxx>
- Date: 31 Aug 2006 10:58:12 -0700
Bilgehan.Balban@xxxxxxxxx wrote:
Hi,
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.");
All sol'ns I came up had various problems in various printf formats.
The closest I had was something like:
#if DEBUG > 0
#define pdebug(fmt ...) printf("%s: " fmt, \
__FUNCTION__, __VA_ARGS__); \
#endif
But this wont work if there's a printf with no va_args, such as:
printf("fmt string and nothing else\n");
because the comma after __FUNCTION__ will be a syntax error.
Any ideas?
#define pdebug(args...) do { \
printf ("%s:", __FUNCTION__); \
printf (args); \
} while (0);
Should do what you want.
Thanks,
Bahadir
.
- Follow-Ups:
- Re: how could I write this cpp macro
- From: Ben Pfaff
- Re: how could I write this cpp macro
- From: Eric Sosman
- Re: how could I write this cpp macro
- References:
- how could I write this cpp macro
- From: Bilgehan . Balban
- how could I write this cpp macro
- Prev by Date: Re: A newbie's code
- Next by Date: Re: how could I write this cpp macro
- Previous by thread: Re: how could I write this cpp macro
- Next by thread: Re: how could I write this cpp macro
- Index(es):
Relevant Pages
|