Ühel kenal päeval, T, 2009-02-10 kell 18:14, kirjutas Peter Stuge:
ron minnich wrote:
The log level is now given with an argument, so it's trickier to get the code excluded from the binary completely.
Maybe split it up then? (But _only_ statics within the printk code!)
Actually it's not that hard.
Yep, that's right.
You have a global , MAXLOGLEVEL. Turn printk into something like this:
#define printk(a, b, ...) if (a <= MAXLOGLEVEL) print(blah blah)
and then let the compiler optimize it all out.
That's what I thought of at first too, but I was discouraged by Mart. Do you see a real problem with this, Mart?
Nope. that's similar to what I had in mind.
Likely can coerce gcc to do that with specially crafted code.
I would prefer to avoid that.
This is very non-special
Yep, it's all at cpp time and not at all strange. I would prefer avoiding compiler tricks when we can reach the goal just using cpp.
Yeah, and if(0) and the like is coercing gcc :)
However I don't think using cpp for this really flies well if we are loosing __attribute__((format (printf, 2, 3))) checks then.
Mart