[linux-elitists] Stupid C tricks

Greg KH greg@kroah.com
Fri Aug 27 21:56:51 PDT 2004

On Fri, Aug 27, 2004 at 06:46:46PM -0700, Jason Spence wrote:
> Something that's been bugging me for a while was the inability to have
> an error reporting macro that automatically outputted the filename and
> line number of the call to the macro, as well as take variable
> arguments in printf(3) format so the programmer could provide some
> information on the state of the program at the time the error occured.
> I figured it out a way to get both last month; please let me know what
> you think.
> http://lightconsulting.com/~thalakan/drop/ngdebug.c

Ick, what about something like what the kernel does in places:

#ifdef DEBUG
#define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg)
#define dbg(format, arg...) do {} while (0)

Put __LINE__ in there too and you are good to go.  Variable length
arguments with a macro, fun stuff (don't mess with the spaces in that
definition, older versions of gcc are very picky...)


greg k-h

More information about the linux-elitists mailing list