|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement
On Mon, 2011-11-28 at 16:40 +0000, Ian Jackson wrote:
> Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl:
> permit declaration after statement"):
> > I think it would make sense to add to the CODING_STYLE that variable
> > declarations shouldn't be mixed with code, unless part of a macro or an
> > alloca-like construct.
>
> I think this is a silly rule. In my proposed commit message I
> advanced three reasons for allowing declaration after statement:
>
> > > * It allows variables to be more often initialised as they are
> > > declared, thus reducing the occurrence of uninitialised variable
> > > errors.
> > >
> > > * Certain alloca-like constructs (arrays allocated at runtime on the
> > > stack) can more often be written without a spurious { } block.
> > > Such blocks are confusing to read.
> > >
> > > * It makes it easier to write and use macros which declare and
> > > initialise formulaic variables and do other function setup code,
> > > because there is no need to worry that such macros might be
> > > incompatible with each other or have strict ordering constraints.
>
> Of these the first two improvements would be banned by your proposed
> coding style rule.
>
> I don't understand what the harm is in allowing declarations, with
> initialisation, freely mixed with code.
Variable declarations should either be at the top of the function or
immediately before / as part of the block which uses them. e.g. this is
unhelpful:
void a_func(void)
{
/* a bunch of code; */
int bar;
/* a bunch more code not using bar */
bar = get_me_a_bar();
/* use bar lots */
}
Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |