Also, the C preprocessor is largely ignorant of C syntax. Am I the only one who finds that incredibly strange?
So perhaps it's more accurate to say preprocessors aren't particularly useful.
OTOH, not having the C pp tied to C means it can be used for other stuff. The only thing I can think of offhand that uses it is the BSD calendar system, though, and that's largely just #include.
I think that's a rather reductionist assessment. See: http://ntu.csie.org/~piaip/plan9/archives/000005.html
So, in other words - yah, you need need a preprocessor with ifdef's, because sometimes there is no other way to do it.
And in other places he basically says he avoided ifdef's by using a fancy makefile, which doesn't seem an improvement to me, since the makefile essentially becomes a (less flexible) pre-processor.
The point about dead-branch pruning instead of ifdef is well taken though. (But there are cases where that doesn't work.)
#ifdef MIPS
mips_stuff();
#endif
should be if (MIPS) {
mips_stuff();
}
Even a mediocre compiler should be able to eliminate the then-body in the non-MIPS case.Another possibility is to generate the same symbols in every architecture specific component and link the one you want to use.
And yes I saw the thing about Plan 9 compiling a kernel for all arch's with no ifdefs - well they only way you can do that is by cheating and either making your own preprocessor, or a fancy makefile. So big whoop.
I read some more, but rapidly came to the conclusion that this is unreadable without the associated (verbal) commentary.