Ron Natalie said:
By making this change, once, with the approval of our design team
and putting it in a controlled place, it gets around a zillion Microsoft
specific hacks that involve bad coding practices of leaving variables
uninitialized or sitting around outside the scope they are used in.
I'm curious why you call it "bad coding practice" to have a single variable
used more than once. I understand that i is in this case just an integer,
and there's no logical reason why it *shouldn't* be declared in each for
loop construct, but what does it hurt to declare it once and use it multiple
times?
Imagine if you had, instead of an integer being used in multiple for loops,
some more complex object being used in multiple blocks of code within one
function. The overhead of constructing the object multiple times now can
outweigh the desired practice of declaring it within each block.
Personally, I prefer to declare i within each loop construct, and then
change that specific piece of code when I port to VC++. If I forget to
change it, the compiler tells me.
Provided that you do not rely on the value of i between or at the start of
any block, but instead assign it a value in the initializer portion of each
for loop, I fail to see where any harm can come from declaring it once and
using it multiple times. (And in the bad old days when I needed every byte
of memory I could get my grubby little hands on, it was practically a
*requirement* that I do it that way!)
-Howard