Combined APM patch
Quoted 8 lines
Quoted 3 lines
Is it not good practice to note when the code _assumes_ zero- initialization? I have seen comments like these elsewhere in the kernel sources.
Comments should _not_ echo code. One should assumes that the reader knows the language. Instead, comments should explain
_whatthepurpose_of that line of code or section of code is if it is not obvious to those that the comments are written to.
I agree that comments should not try to explain C to the reader. Comments should provide additional information, such as telling the reader what the code is supposed to do (as opposed to what it actually does, which may or may not be the same thing).
In the line
static int suspends_pending; /* = 0 */
the comment is not there to tell the reader that the variable is initialized to zero. It is there to tell the reader that the variable _needs to be_ initialized to zero in order for the code to work properly. This is useful information, because if someone later wants to modify the code to make this variable non-static, the comment tells that person that the variable will need an initializer.
--
Thomas
Quoted 4 lines · Thomas Hood
This is useful information,
because if someone later wants to modify the code to make this variable non-static, the comment tells that person that the variable will need an initializer.
Whether a variable is static or not doesn't change whether it ends up in the bss segment or not.
/* top level */
static int foo;
int bar;
Both foo and bar will be initialised to 0 - since they're both placed into the BSS segment (or maybe its common subsection):
$ gcc -S -o - t.c @ Generated by gcc 2.96 20000731 (Red Hat Linux 7.1 2.96-80) for ARM/elf .file "t.c" gcc2_compiled.: .bss .align 2 foo: .space 4 .comm bar, 4 @ 4
$ gcc -S -o - t.c -fno-common @ Generated by gcc 2.96 20000731 (Red Hat Linux 7.1 2.96-80) for ARM/elf .file "t.c" gcc2_compiled.: .bss .align 2 foo: .space 4 .global bar .align 2 .type bar,object .size bar,4 bar: .space 4
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Quoted 7 lines · Russell King
Quoted 3 lines · Thomas Hood
if someone later wants to modify the code to make this variable non-static, the comment tells that person that the variable will need an initializer.
Whether a variable is static or not doesn't change whether it ends up in the bss segment or not.
It does make a difference if the variable definitions are inside a function; the non-static variable is on the stack and is not initialized to zero.
I understand that every static or top-level global variable is initialized to zero; but is it not useful to note when the code _relies upon_ this zero-initialization?
Quoted 6 lines · Thomas Hood
Quoted 5 lines · Russell King
Quoted 3 lines · Thomas Hood
if someone later wants to modify the code to make this variable non-static, the comment tells that person that the variable will need an initializer.
Quoted 6 lines
Quoted 2 lines
Whether a variable is static or not doesn't change whether it ends up in the bss segment or not.
It does make a difference if the variable definitions are inside a function; the non-static variable is on the stack and is not initialized to zero.
I should really ignore this mail, but, sigh.
I know this. I was commenting on your code and the comment you made which, in the context you were applying it, wasn't correct.
Hope this clears up the confusion.
Quoted 3 lines
I understand that every static or top-level global variable is initialized to zero; but is it not useful to note when the code
_reliesupon_this zero-initialization?
Of course, I'm not disputing that.
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html