B
Bilgehan.Balban
Hi,
I've heard somewhere that Plan9 OS did not use #ifdefs in the
preprocessor but only #ifs. The argument was that #ifdefs make code
less readable. Now that when I read linux kernel code, especially for
distinguishing architecture specific code a lot of #ifdef statements
are used. Same applies for eCos, and that one is I think much less
readable due to #ifdefs.
Surely conditional compilation is a necessity and thats why they
couldn't get away without #ifdefs. My question is, how would one manage
conditional compilation best in C, such that the code is more readable.
For example the following is an #ifdef trick used in the linux kernel:
#ifdef CONDITION
void func(void) {
}
#else
void func(void) {
/* Code that actually does something */
}
#endif
This increases the readability of the code, due to the fact that the
call to func() is left untouched regardless of the condition. Do you
know similar #ifdef management tricks? How could one write code with
least #ifdefs and best readability?
Thanks,
Bahadir
I've heard somewhere that Plan9 OS did not use #ifdefs in the
preprocessor but only #ifs. The argument was that #ifdefs make code
less readable. Now that when I read linux kernel code, especially for
distinguishing architecture specific code a lot of #ifdef statements
are used. Same applies for eCos, and that one is I think much less
readable due to #ifdefs.
Surely conditional compilation is a necessity and thats why they
couldn't get away without #ifdefs. My question is, how would one manage
conditional compilation best in C, such that the code is more readable.
For example the following is an #ifdef trick used in the linux kernel:
#ifdef CONDITION
void func(void) {
}
#else
void func(void) {
/* Code that actually does something */
}
#endif
This increases the readability of the code, due to the fact that the
call to func() is left untouched regardless of the condition. Do you
know similar #ifdef management tricks? How could one write code with
least #ifdefs and best readability?
Thanks,
Bahadir