[PATCH 1/4] staging: comedi: make 'dev->attached' a bool bit-field

H Hartley Sweeten hartleys at visionengravers.com
Fri Mar 15 16:43:49 UTC 2013


On Friday, March 15, 2013 9:16 AM, Greg Kroah-Hartman wrote:
> On Fri, Mar 15, 2013 at 01:15:33PM +0000, Ian Abbott wrote:
>> Change the `attached` member of `struct comedi_device` to a 1-bit
>> bit-field of type `bool`.  Change assigned values to `true` and `false`
>> and replace or remove comparison operations with simple boolean tests.
>> 
>> We'll put some extra bit-fields in the gap later to save space.
>> 
>> Signed-off-by: Ian Abbott <abbotti at mev.co.uk>

<snip>

>> +	bool attached:1;
>
> I'm not objecting to this, but for some reason I thought that bit fields
> could only be a 'unsigned int'.  Or am I just used to C88 or some such
> really old spec of the C standard?

I'm not sure about this either.

Using bit fields with a bool is found in the kernel but it's not very common.
A quick grep shows these:

drivers/block/DAC960.h
drivers/md/dm-cache-metadata.c
drivers/md/dm-cache-policy-cleaner.c
drivers/md/dm-cache-policy-mq.c
drivers/md/dm-cache-target.c
drivers/md/dm-thin-metadata.c
drivers/md/dm-thin.c
drivers/md/persistent-data/dm-bitset.h
drivers/md/persistent-data/dm-block-manager.c
drivers/md/persistent-data/dm-space-map-common.h
drivers/pinctrl/pinctrl-nomadik.h
drivers/scsi/BusLogic.h
drivers/scsi/sr.h
drivers/target/iscsi/iscsi_target_core.h
drivers/usb/host/ehci.h
drivers/video/omap2/dss/dispc.c
fs/cifs/cifsglob.h
fs/fuse/fuse_i.h
include/acpi/acpi_bus.h
include/linux/device-mapper.h
include/linux/pm.h
include/linux/pm_wakeup.h
include/linux/sysfs.h
include/target/target_core_base.h
kernel/printk.c
net/dccp/feat.h
sound/pci/hda/hda_local.h

I guess the real question is, what's the underlying type of a bool?
It must be an unsigned "something" or the compiler would complain.
And does assigning a bit field to the bool actually save any space?

<linux/types.h>	typedef _Bool bool;

_Bool is a standard type in C99

I found this:

http://gcc.gnu.org/ml/gcc-patches/2000-10/msg01127.html

But honestly still don't know what a _Bool is... :-)

Regards,
Hartley




More information about the devel mailing list