On (30/08/15 15:31), Simo Sorce wrote:
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.
We should avoid mass converting to this style. The new approch
should be only used as part of rewriting function or in new functions.
BTW Should it be recommended or just allowed to use?
LS