Can we move Samba to C99 and past -Werror=declaration-after-statement ?

Andreas Schneider asn at samba.org
Tue Nov 14 13:13:17 UTC 2023


On Friday, 10 November 2023 10:44:23 CET Stefan Metzmacher via samba-technical 
wrote:
> Am 09.11.23 um 23:13 schrieb Martin Schwenke via samba-technical:
> > On Fri, 10 Nov 2023 10:58:04 +1300, Andrew Bartlett via samba-technical
> > 
> > <samba-technical at lists.samba.org> wrote:
> >> Samba chooses to, for it's C style guide, to enforce -
> >> Werror=declaration-after-statement
> >> 
> >> I understand that some prefer the style.
> >> 
> >> However C has moved on as a language, and libraries we use (Python 3.12
> >> in this case) don't compile with it, and we are having to do quite some
> >> contortions in
> >> https://gitlab.com/samba-team/samba/-/merge_requests/3373 to build on
> >> Fedora 39.
> >> 
> >> See also discussion at https://bugzilla.samba.org/show_bug.cgi?id=15513
> >> 
> >> Can we agree to just remove this requirement?
> >> 
> >> It will allow us to keep variables closer to their use, which is
> >> helpful in a lot of ways, particularly in longer functions.
> > 
> > I think that sounds good.  Yes from me.
> 
> I'd like to keep -Werror=declaration-after-statement as long as possible.
> 
> Variables appearing in the middle of a function, particularly in longer
> functions, are really confusing to me. Thinks like common cleanup via goto
> would not know of a variable exists yet...

I'm also in favor of having all the variable declarations in one place. We 
have LSP in the meantime and it is easy to figure out the type of variables.
 
> And every time I saw a patch with the use a declaration in the middle,
> I immediately thought this would lead to sloppy coding if we would allow
> that everywhere.

I just checked, at least clangd creates an error for this in neovim:

clang: Variable 'wurst' is used uninitialized whenever 'if' condition is true 
(fix available)

gcc didn't complain.

> > Can we also please declare for loop variable in the loop?
> 
> These would be very useful and I just checked they also work with
> /opt/IBM/xlC/16.1.0/bin/xlC on AIX.
> 
> metze


-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D





More information about the samba-technical mailing list