Date: Mon, 24 Aug 2009 01:54:43 +1000 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Christoph Mallon <christoph.mallon@gmx.de> Cc: Ed Schouten <ed@80386.nl>, src-committers@FreeBSD.org, svn-src-all@FreeBSD.org, Bruce Evans <brde@optusnet.com.au>, svn-src-head@FreeBSD.org, Julian Elischer <julian@FreeBSD.org> Subject: Re: svn commit: r196451 - head/sys/netinet/ipfw Message-ID: <20090824013656.M38813@delplex.bde.org> In-Reply-To: <4A9155BA.9020808@gmx.de> References: <200908230759.n7N7xS6g051165@svn.freebsd.org> <20090823080940.GT1292@hoeg.nl> <20090823230300.Q38728@delplex.bde.org> <4A9155BA.9020808@gmx.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090824013656.M38813>