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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday, March 15, 2013 9:43 AM, Ian Abbott wrote:
> On 2013-03-15 16:16, Greg Kroah-Hartman wrote:
>> On Fri, Mar 15, 2013 at 01:15:33PM +0000, Ian Abbott wrote:
>>> --- a/drivers/staging/comedi/comedidev.h
>>> +++ b/drivers/staging/comedi/comedidev.h
>>> @@ -207,7 +207,7 @@ struct comedi_device {
>>>
>>>   	const char *board_name;
>>>   	const void *board_ptr;
>>> -	int attached;
>>> +	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?
>
> It's used elsewhere in the kernel in quite a few places, e.g. in 
> "kernel/printk.c" for the `flushed` member of `static struct cont`.
>
> C99 certainly allows `_Bool` bit-fields (and a `bool` is a `_Bool` in 
> the kernel).

In case anyone is interested...

I created a test case with 4 structs.

	struct test1 {
		unsigned int var0;
		...
		unsigned int var8;
	};

	struct test2 {
		unsigned int var0:1;
		...
		unsigned int var8:1;
	};

	struct test3 {
		_Bool var0;
		...
		_Bool var8;
	};

	struct test4 {
		_Bool var0:1;
		...
		_Bool var8:1;
	};

A quick test with gcc 4.4.5 shows this:

sizeof(test1): 36
sizeof(test2): 4
sizeof(test3): 9
sizeof(test4): 2

It appears the underlying type is an unsigned char and using
bit fields is not a problem.

Regards,
Hartley

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux