On March 13, 2017 8:16:28 AM EDT, Maxime Coste <[email protected]> wrote:
>Either way is fine by me, being a C++ developper I have a bias towards
>declaring variables as close as possible to their place of use

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.

I don't claim to be an expert, so take this with a grain of salt. I'm going 
only on what I've read about for optimization of code and I could be wrong. 
Maybe someone with more experience than me can weigh in.

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to