lkml.org 
[lkml]   [2000]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subject#ifdefs vs. unused variables?
Hi.

Various parts of the kernel, notably the drivers, have sections
of code that is only relevant if certain defines are valid. The
obvious examples would be CONFIG_PROC_FS and MODULES. In both
cases the functions directly used in conjunction with these
defines evaluate to nops. But especially in the case of
CONFIG_PROC_FS helper functions are defined that are, in the case
where the define is undefined :), left unused but still compiled
into the object file. The best example of this I have found to
date is the advansys driver which (roughly) goes from 110K to 80K
if CONFIG_PROC_FS is undefined (and the appropriate #ifdefs are
placed).

The obvious way to fix this would be to place the necessary
#ifdefs in the code but ifdefs are not nice and some think they
should be avoided at all cost.

My question now is: What is the Right Thing to do? (I realise that
there probably are many opinions on this subject but perhaps some
of the people with high karma might make their feelings known?)

I see three scenarios for placing/not placing #ifdefs:

1) The code is purely functions that evaluate to noops if the
define is not set. E.g., create_proc_entry. An #ifdef here would
basically only underscore what the careful reader would already
know :)

2) The code is basically like 1) but with some conditionals/
support code around. drivers/block/cpqarray.c::ida_procinit would
be an example (yes, I know that it already has an ifdef around
it).

3) The code in question is variable definitions only used when
the define is valid. (Still in cpqarray.c) proc_array would be an
example of this.

4) The code in question is a support function for code like 1)
and 2) but not itself surrounded by #ifdefs. An example would be
arc_prt_board_devices from drivers/scsi/advansys.c.

OK, so that was four :)

My feeling would be that 1) and 2) would not require ifdefs. 3)
is trickier but for cleanliness sake we might forego the ifdefs
and endure the compiler warnings (but I dont like those!) and 4)
would be a good case to put in #ifdefs.

Comments? Was this even intelligible?

--
Regards,
Rasmus(rasmus@jaquet.dk)

It is wonderful to be here in the great state of Chicago.
-Former U.S. Vice-President Dan Quayle
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:45    [W:0.028 / U:6.608 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site