Messages in this thread |  | | From | Keith Owens <> | Subject | RFC - addition to Documentation/CodingStyle | Date | Wed, 15 Jan 1997 20:18:29 +1100 |
| |
I'd like to add the following to CodingStyle, either at the end of chapter 3 (naming) or as a standlone chapter (scoping). Any comments?
============= start
Only variables and functions that are used by another source should be declared as global. Variables and functions that are only used by the current source should be declared as static. Declaring a name as static has several advantages :-
It makes it obvious that it is only used in the current source. No need to hunt through the rest of the kernel to see if any other code refers to the name.
The compiler will flag unused static variables, it cannot flag unused global variables.
It greatly reduces the chance that two sources will have the same global symbol. Otherwise the linker complains about multiply defined symbols.
No need to define static names in header files, reducing the cross source impact of a change.
To save space on rescue and install disks, modules may be stripped. Static names can be removed (saving space), global ones cannot.
============= end
A note on that last point. At the moment it is not really safe to strip modules. Some modules already define the insmod target variables as static. Blindly stripping such a module deletes the static symbols and insmod does not work very well.
With the addition of MODULE_PARM, it is now safe to define the insmod variables and functions (including init_module and cleanup_module) as static. Then do a selective strip of the module, discarding most static names and keeping those required by insmod. A script to do this is being tested at the moment.
|  |