Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/fs/tmpfs

Masao Uebayashi <> wrote:
> >> The kernel explicitly allows C99 and actually C99 is encouraged.
> >> So that should reverted :)
> >
> > Generally - C99 is encouraged.  However, I disagree that variables
> > should be declared in the middle of context (for a minimum scope),
> > unless there is a *clear* benefit.  Otherwise, it makes code harder
> > to read, especially if code fragment is long and/or complex.
> I disagree.  If variables are declared in the middle of context, those
> variables have narrower contexts.  Narrowing context is always a win
> IMO.
> I'd like to hear the benefit not doing this (== the old convention).

Benefit is code readability.  It is easier to track the variables when
they are defined and initialised in the beginning of context.

If code is longer and/or complex - it likely has loops or conditional
statements, and variables can be defined in the beginning of *their*
context (basically, after { bracket).  This is very encouraged.

For other cases, compilers do a good job anyway (if you do not believe
me - check with objdump) and there is no need to hurt code readability.  

> >
> > Benefits could be, e.g. use of const or limitation of the variable
> > scope for performance sensitive code, also avoiding of #ifdefs, etc.
> >
> > In this case, I used for (int i = 0; ...) because the loop was in
> > the beginning of context and #ifdef DEBUG-only.
> >
> > --
> > Mindaugas
> >


Home | Main Index | Thread Index | Old Index