On Fri, 2015-08-28 at 09:03 +0200, Petr Cech wrote:
Hi everyone,
I would like to ask you what you think about the initialization of
iterative variables in forloops. I know that present code style does not
allow it. But how I recognized, we use C99, and this feature is here now.
(example)
Instead of:|
|||# inti;
# for(i =0;...)|||
we could write:
||# for(inti =0;...)|
I see an advantage in limiting the validity of such variables. That
means higher code readability. Disadvantages I searched but did not find.
I think it is ok to accept this style when there is *only one* variable
involved and the iterator variable is useful exclusively within the for
loop. I used this style elsewhere and it was ok.
Much care need to be taken when *converting* code to this style, because
in many case the index is used after the for loop to check for
failure/success when the loop breaks in the middle.
Simo.
P.S: please do not use HTML emails, see how butchered your email comes
out in the txt version.
--
Simo Sorce * Red Hat, Inc * New York