lkml.org 
[lkml]   [2014]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH v8 net-next 1/3] filter: add Extended BPF interpreter and converter
    From
    Date
    On Mon, 2014-03-10 at 19:02 -0700, Linus Torvalds wrote:
    > On Mon, Mar 10, 2014 at 6:51 PM, David Miller <davem@davemloft.net> wrote:
    > > From: Alexei Starovoitov <ast@plumgrid.com>
    > > Date: Sun, 9 Mar 2014 23:04:02 -0700
    > >
    > >> + unsigned int jited:1;
    > >
    > > The C language has a proper type for boolean states, please therefore
    > > use 'bool', true, and false.
    >
    > No, the C standard actually has no such thing.
    >
    > In a structure, a bitfield is actually better than bool, because it
    > takes only one bit. A "bool" takes at least a byte.

    Bitfields can also be _Bool and at least for gcc
    _Bool bitfields are required to be :1.

    > Now, in this case it may not be an issue (looks like there are no
    > other uses that can use the better packing, so bit/byte/word is all
    > the same), but I really really want to make it clear that it is not at
    > all true that "bool" is somehow better than a single-bit bitfield. The
    > bitfield can pack *much* better, and I would actually say that it's
    > generally a *better* idea to use a bitfield, because you can much more
    > easily expand on it later by adding other bitfields.

    bitfields generate relatively poor code and are frequently
    disadvantageous due to read-modify-write requirements.

    > There are very few actual real advantages to "bool". The magic casting
    > behavior is arguably an advantage (the implicit cast in assigning to a
    > bitfield truncates to the low bits, the implicit cast on assignment to
    > "bool" does a test against zero), but is also quite arguably a
    > possible source of confusion

    Umm. Types are good.

    > and can cause problems down the line when
    > converting from bool to a bitfield (for the afore-mentioned packing
    > reasons).

    I don't see how.

    > I would generally suggest that people only use "bool" for function
    > return types, and absolutely nothing else. Seriously.

    I think using bool for function arguments, structure members and
    variables is good and frequently to mostly is an overall improvement.




    \
     
     \ /
      Last update: 2014-03-11 04:41    [W:5.362 / U:0.508 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site