Here's a (second) toy problem:
Suppose I have a large program with lots of C files.
I have debugging code in all the files. Debug code is prefixed by DB and perhaps some ids, e.g.:
Code:
DB printf(stderr, "Started on this file");
DB(3) printf(stderr, "doingstuff");
DB(anchor) printf(stderr, "doingotherstuff");
DB(3,anchor) printf(stderr, "never done this before!")
I have a .h file which controls debug output. Debugging can be switched on & off for each file, for each id, or for a combination of both:
Code:
DB_ON shluck.c 3 # db code in the indicated file at level 3.
DB_ON anchor # db code with the anchor keyword
Finally, the code has to run fast, so the debug code really does have to be taken out by the preprocessor, not replaced by a C runtime check.
What tools does the C preprocessor have to help with this? Well, it has keywords for the current file name and it has concatenating ability. So it's pretty easy to make a runtime check for filenames:
#define DB if ( debug_##__FILE )
(or whatever it is - my trusty preprocessor manual is out of reach)
A couple of us put our heads together a few months ago (when I asked this one) and worked out how to deal with the keywords as well, and the result was really ugly. Also, it yet again involved runtime checks, so ran dog slow.
So, how do I do it using purely the pre-processor?
If I could use bash or perl as a preprocessing language I'd be happy.
I'll check the with-cpp option, thanks gnashley.
grumpfs: You mention that it's not only possible but easy to extend the pre-processor with other scripting languages. That sounds interesting. Can you show me some examples, or a page with a mini-essay on how to do this?
Regards, Hakenbein