Re: [Announce] Linux-tiny project revival

Dick Streefland
2007-09-21T13:29:35Z

Rob Landley <rob@landley.net> wrote:
| I'm proposing allowing an ignore_loglevel to remove the unused messages at
| compile time so they don't take up space. Doing that requires the levels to
| be integers so they can be compared with < or >, and the remaining changes
| follow logically. (To me, anyway...)

Gcc seems to be smart enough to do contant folding on string
subscripts, so you don't need to change any of the printk()s.
Here is what I mean:

#include <stdio.h>

#define actual_printk printf

#define KERN_ERR "<3>" /* error conditions */
#define KERN_WARNING "<4>" /* warning conditions */
#define KERN_NOTICE "<5>" /* normal but significant condition */

#define printk(str, ...) \
do { \
if ((str)[0] != '<' || (str)[1] < '5') \
actual_printk((str), __VA_ARGS__); \
} while(0);

int main(void)
{
printk(KERN_ERR "error %d\n", 1);
printk(KERN_WARNING "warning %d\n", 2);
printk(KERN_NOTICE "notice %d\n", 3);
printk("no level %d\n", 4);
return 0;
}

--
Dick Streefland //// Altium BV
dick.streefland@altium.nl (@ @) http://www.altium.com
--------------------------------oOO--(_)--OOo---------------------------