[PATCH] Add utilities to check style

Simo simo at samba.org
Tue Apr 24 17:30:27 UTC 2018


On Tue, 2018-04-24 at 08:51 +0200, Swen Schillig via samba-technical
wrote:
> On Mon, 2018-04-23 at 11:48 -0400, Simo via samba-technical wrote:
> > On Mon, 2018-04-23 at 16:13 +1000, Martin Schwenke wrote:
> > > On Sat, 21 Apr 2018 17:34:12 -0400, Simo via samba-technical
> > > <samba-technical at lists.samba.org> wrote:
> > > 
> > > > > 
> > > 
> > > * The "Un-cuddled open brace" thing is going to be annoying
> > > 
> > >   If you're initialising an array of structures then I don't see
> > > how
> > >   you can avoid this warning.
> > > 
> > >   Similarly, when initialising a fairly long array of structures
> > > you
> > >   might want to have the values inline, with opening and closing
> > > braces
> > >   on the same line as the data.  However, this generates lots of
> > >   complaints.  :-(
> > 
> > I do not see why we want this to be a thing to be honest,.
> > 
> > We do:
> >   struct foo bar = {
> >     data
> >   }
> > We do not do:
> >   struct foo bar = 
> >   {
> >      data
> >   }
> > do we ?
> 
> what about 
>   struct foo bar = {0};

What about it ?
Just to be clear, this check prevents a bare { opened on a line of its
own and not on the first column.
So.

int foobar(void)
{

is fine

while 
   for (;;)
   {

is not.

I think this is the desired style we use in most code. There are some
instances where we used a code block hanging on its own in places, but
that was never sanctioned and I personally think it is bad style. It
was done before C99 when declaring variables could be done only at the
start of a code block and we wanted some variables to be local, but we
do not have that restriction anymore, and in either case, if you have
that need it really means you should have a helper function in there
anyway, rather than a new hanging code block.

HTH,
Simo.



More information about the samba-technical mailing list