Mail Archives: djgpp/2000/01/01/20:49:25
> >Yes, I know that a bit field can be defined as short, in which case, it
> >would occupy a short int, equal to 2 bytes, but in my structure, I
defined
> >the bit fields inside an unsigned int. Shouldn't that force the length of
> >the bit fields to be 4, and any other stuff in the structure should be
added
> >to that?
> >
>
> But the bit fields did not use all the space so the compiler is free to
> add or subtract additional space as it see fit.
> Since in thoeory you are not using this extra space. If you are using
> the extra space you should define it.
>
Thanks, David, I think I had misunderstood the meaning of the definition of
a bit field. I don't have a copy of K&R, but I looked it up in the library.
I had previously learned that when I defined :
unsigned bit_field: 6;
.. it meant that 6 bits of an unsigned int would be used for my bit field.
The length used up in the structure would necessarily be sizeof)unsigned). I
now reallise that it is the 6 bit field which contains an unsigned number,
as it might have contained a signed one. I had not reallised that you could
define:
int bit_field_1:3,
bit_field_2:6;
... and that both bit fields would contain signed numbers.
Well, you live and learn.
My thanks to yourself and Phrasant, who also spent time with me on e-mail
trying to sort this out, and my apologies to DJGPP, which doesn't have a bug
after all!
Mike.
- Raw text -