Question about the code...

Ted Lemon Ted.Lemon at nominum.com
Fri Feb 6 21:23:42 UTC 2009


On Feb 6, 2009, at 2:01 PM, Robert Heller wrote:
> I suspect that I might have worked with early C
> run-time environments that did not follow this spec (like the early
> pre-ANSI C compilers available under CP/M-68K, OS9/68K, and SunOS  
> 3.x),
> so I learned NOT to trust that global variables would be implicitly
> initialzed to anything in partitular.

Compilers aimed at embedded systems often did not honor this rule, but  
the rule goes all the way back to K&R.   There are a lot of things you  
could put into the code to support broken old compilers and operating  
systems, but at some point you have to ask yourself whether or not  
it's worth it to protect people from themselves like that.   I don't  
know of any modern compiler that has the problem you describe.   So in  
my mind, explicitly initializing static variables to zero is bad style  
- similar to this:

	if (a == 0) {	/* check to see if a is zero. */

If you don't know C, and aren't a programmer, the comment may be of  
some value to you.   But there's no hierarchy of comments, so this  
comment is weighted just as strongly as a comment that explains  
something that wouldn't be obvious even to an experienced C  
programmer.   By devaluing the second type of comment, it renders the  
program less understandable, and is therefore bad style.




More information about the dhcp-users mailing list