RE: [PATCH net-next v2 0/3] introduce skb_for_each_frag()

From: David Laight
Date: Sat Apr 17 2021 - 07:08:04 EST


From: Matteo Croce
> Sent: 16 April 2021 23:44
...
> > A more interesting change would be something that generated:
> > unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
> > for (i = 0; i < nr_frags; i++) {
> > since that will run faster for most loops.
> > But that is ~impossible to do since you can't declare
> > variables inside the (...) that are scoped to the loop.
> >
>
> I don't know how to do it with C90.
> It would be nice to have a switch to just allow declaration of
> variables inside the (...) instead of enabling the full C99 language
> which, as Linus said[1], allows the insane mixing of variables and
> code.
>
> [1] https://lore.kernel.org/lkml/CA+55aFzs=DuYibWYMUFiU_R1aJHAr-8hpQhWLew8R5q4nCDraQ@xxxxxxxxxxxxxx/

Quoting Linus:

> I *like* getting warnings for confused people who start introducing
> variables in the middle of blocks of code. That's not well-contained
> like the loop variable.

The really stupid part of C99 is that such variables can alias
ones in an outer block.
Aliased definitions are bad enough at the best of times.
Makes it very easy to miss the correct definition when reading code.

I much prefer local variables to either function scope or be
defined for very local use at the top of a very small block.

David

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