On Mon, Mar 13, 2017 at 09:30:56AM -0400, Jody Lee Bruchon wrote:
> Given that BusyBox is intended to be as small as possible since it is 
> targeted at embedded platforms, I'd say that declaring variables inside of a 
> code block which are used only within a code block is better. Not only does 
> it de-clutter the top of the function, it also tells the compiler that the 
> variable is local to that code block which can help with optimization. The 
> compiler may be smart enough to notice this anyway, but it doesn't hurt to 
> remove all doubt.
> 
> The only instance I can think of where this wouldn't be proper is if you use 
> a throwaway variable like 'i' for counting something and reuse it later in 
> the function (after its first use won't ever be needed again, of course) to 
> save on stack variable allocations. It makes more sense to me for embedded 
> platform code to reuse such variables instead of ending up with a pile of i, 
> j, k, etc. consuming more space unnecessarily. However for a single use in a 
> loop it should be declared within the code block.
Even for that, I'd expect modern compilers to reuse the same stack space for 
these, as it can very easily see their use dont overlap.

Regarding the point of declaration of variables, I am a bit confused now, I see 
there are different opinions, but I dont know who has the last word on such 
matter.

I'd be happy to do whichever change is needed once its decided, along with 
preparing a proper commit message. Is there anything else preventing this from 
being pushed upstream ?

Cheers,

Maxime.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to