lkml.org 
[lkml]   [2019]   [Oct]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] media: si2168: use bits instead of bool for flags
Em Thu, 10 Oct 2019 08:34:23 -0300
Mauro Carvalho Chehab <mchehab+samsung@kernel.org> escreveu:

> Em Thu, 10 Oct 2019 12:55:44 +0200
> Gon Solo <gonsolo@gmail.com> escreveu:
>
> > On Fri, Oct 04, 2019 at 10:15:22AM -0300, Mauro Carvalho Chehab wrote:
> > > Using bool on struct is not recommended, as it wastes lots of
> > > space. So, instead, let's use bits.
> >
> > Wouldn't "bool b:1;" even be better? I performed a little test:

> > Result:
> >
> > bit_uints: 4
> > bit_bools: 1

> > I know with different types within the struct it looks different, but
> > still.
>
> No. In practice, the compiler will add 3 bytes of pad after bit_bools
> (on 32-bit archs), due to performance reasons.

Btw, if you want to test, just add something after the bits, and you'll
see that it will now report the PAD bytes too:

struct bit_uints {
unsigned int a0:1;
unsigned int a1:1;
unsigned int a2:1;
unsigned int a3:1;
unsigned int a4:1;
unsigned int a5:1;
unsigned int a6:1;
unsigned int a7:1;

int i;
};

struct bit_bools {
bool a0:1;
bool a1:1;
bool a2:1;
bool a3:1;
bool a4:1;
bool a5:1;
bool a6:1;
bool a7:1;

int i;
};

bit_uints: 8
bit_bools: 8

Thanks,
Mauro

\
 
 \ /
  Last update: 2019-10-10 13:44    [W:0.058 / U:1.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site