lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 10 Oct 2019 08:34:23 -0300
From:   Mauro Carvalho Chehab <mchehab+samsung@...nel.org>
To:     Gon Solo <gonsolo@...il.com>
Cc:     Linux Media Mailing List <linux-media@...r.kernel.org>,
        Mauro Carvalho Chehab <mchehab@...radead.org>,
        JP <jp@...w.nl>, crope@....fi, Sean Young <sean@...s.org>,
        Linux Kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/4] media: si2168: use bits instead of bool for flags

Em Thu, 10 Oct 2019 12:55:44 +0200
Gon Solo <gonsolo@...il.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:
> 
> #include <stdbool.h>
> #include <stdio.h>
> 
> struct uints {
> 	unsigned int a0;
> 	unsigned int a1;
> 	unsigned int a2;
> 	unsigned int a3;
> 	unsigned int a4;
> 	unsigned int a5;
> 	unsigned int a6;
> 	unsigned int a7;
> };
> 
> struct bools {
> 	bool a0;
> 	bool a1;
> 	bool a2;
> 	bool a3;
> 	bool a4;
> 	bool a5;
> 	bool a6;
> 	bool a7;
> };
> 
> 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;
> };
> 
> 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 main() {
> 	printf("bit_uints: %ld\n", sizeof(struct bit_uints));
> 	printf("bit_bools: %ld\n", sizeof(struct bit_bools));
> 	printf("uints: %ld\n", sizeof(struct uints));
> 	printf("bools: %ld\n", sizeof(struct bools));
> }
> 
> Result:
> 
> bit_uints: 4
> bit_bools: 1
> uints: 32
> bools: 8
> 
> 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.

Using "unsigned int" makes it clearer.

Thanks,
Mauro

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ