svn commit: r196451 - head/sys/netinet/ipfw

Bruce Evans brde at optusnet.com.au
Sun Aug 23 15:54:54 UTC 2009


On Sun, 23 Aug 2009, Christoph Mallon wrote:

> Bruce Evans schrieb:
>> %  */
>> % int
>> % ipfw_init(void)
>> % {
>> %     int error = 0;
>> 
>> This variable is not really used.
>> 
>> Initialization in declaration.  This mainly obfuscates the non-use of the
>> variable.
>
> Rather the opposite is true:
>
> void f(void)
> {
>  int error = 0; // GCC warns that error is unused
> }
>
> void g(void)
> {
>  int error;
>  error = 0; // GCC is silent
> }

Interesting.  A bug in gcc.  Even the primitive lint(1) in FreeBSD warns
about both (it says "set but not used"; if the variable is not even set,
then it says "unused").

> In this case it does not help, because error is used. But an assignment 
> halfway down the function definitely would not improve the situation.

The assignment should be just before the first use of the variable (if
the first use is conditional, this may be impossible, but then an
initialization at the start of the function would increase the
obfuscation).  In this case, the first use is in the return statement
and it would then be obvious to everyone except the compiler that both
the variable and its initialization are bogus:

 	error = 0;
 	return (error);

A non-KNF style would put the declaration next to the use.  Then the bogusness
would be even more obvious:

#if __STDC_VERSION__ < 199901
 	{
#endif
 		int error;

 		error = 0;
 		return (error);
#if __STDC_VERSION__ < 199901
 	}
#endif

Bruce


More information about the svn-src-all mailing list