lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 14 Apr 2008 13:52:59 +0200
From:	"Hans J. Koch" <hjk@...utronix.de>
To:	Russell King - ARM Linux <linux@....linux.org.uk>
Cc:	Uwe Kleine-König <Uwe.Kleine-Koenig@...i.com>,
	"Hans J. Koch" <hjk@...utronix.de>,
	Greg Kroah-Hartman <gregkh@...e.de>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Re: [PATCH 4/4 v2] [RFC] UIO: generic platform driver

On Mon, Apr 14, 2008 at 12:37:59PM +0100, Russell King - ARM Linux wrote:
> On Mon, Apr 14, 2008 at 01:20:21PM +0200, Uwe Kleine-König wrote:
> > [1] http://lkml.org/lkml/2008/4/11/81 or
> > http://thread.gmane.org/gmane.linux.kernel/665257
> 
> In one of the mails, it was said:
>   No. It's more important to see which variables are declared in the
>   function and which are declared elsewhere. If you have to search the
>   whole body of a function for possible declarations, this is BAD. And if
>   it's not clear where a variable is used, the function is too long or has
>   other style problems. Your function is short and clean, so where's the
>   problem? Please move the declaration to the top of the function.
> 
> I disagree with this statement.  It's far better to limit the scope of
> variables so that you know they only have local use, and eg, not used
> inside a loop and then outside with possible unintended effects.
> 
> If a variable is only used inside a loop, it should be declared _inside_
> that loop.
> 
> The statement goes on to talk about the function being short and clean -
> that's not an argument to apply any particular point of view on this
> subject, since you can argue that because it's short and clean you can
> see that the variable is only used within the loop.
> 
> So, please, keep the variable declaration inside the loop, and don't
> pollute the outer levels with unnecessary variable declarations.

OK, I'm finally convinced :-)
I knew this style from C++ where it makes sense, because a (class-)
variable declaration can implicitly call the constructor of that class
which you normally want to avoid if not needed. As this doesn't happen
in C, I found it unnecessary.
I agree now that there's also a readability argument. The limitation of
the scope is probably not that important as compilers will optimize that
anyway in a lot of cases.

Thanks,
Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ