Subject: Re: Bitfields and kernel
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 09/29/1999 12:47:15
> Is there any inherent reason why using bitfields in the kernel would
> be evil?

I'd say no.

> typedef struct {
>   unsigned int reserved0_12:13;
>   unsigned int pow:1;
>   unsigned int reserved14:1;
>   unsigned int ile:1;
>   ...
> } reg_msr_t;
> reg_msr_t msr;
> msr.pow = 1;
> msr.ile = 0;

The biggest problem with this, aside from the nonportability various
people have commented on, is that it becomes impossible to manipulate
multiple bits at the same time.  This can be important for setting and
clearing bits and can be useful when testing bits.

> IMHO, using bitfields is easier to maintain and understand, and less
> prone to errors.

*shrug*  I disagree.

Until someone comes up with statistics from a study, this question will
have to remain unsettled in general.

More important, which is more comfortable for our kernel hackers?  For
what it's worth, I feel more comfortable with #defines.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B