RE: [PATCH] kbuild: drop -Wdeclaration-after-statement

David Laight
2022-10-29T11:47:39Z

From: Alexey Dobriyan
> Sent: 28 October 2022 21:55
>
> On Fri, Oct 28, 2022 at 01:29:08PM -0700, Linus Torvalds wrote:
> > On Fri, Oct 28, 2022 at 1:00 PM Alexey Dobriyan <adobriyan@gmail.com> wrote:
> > >
> > > Putting declarations in the beginning of the block is an afterfact from
> > > single pass compiler era. Compiler would parse all declarations, layout
> > > stack frame and proceed to generate code.
> >
> > No, putting declarations at the beginning is still kernel syntax.
> >
> > Don't declare variables in multiple places. It gets really confusing.
>
> It is not. Somehow millions of programmers manage to find their
> variables just fine in C and other programming languages.

Have you ever tried it when -Wshadow isn't enabled and variables
with the same name are redefined in the middle of blocks?

C++ has to allow it (and it is annoying to find definitions)
because the initialiser has to be called.
But you can't use a 'goto' to jump past a declaration.

> > Put all declarations at the top of the block they are contained in.

Or better, either at the top of the function or in a small block
(where the limited scope is absolutely obvious).

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)