M
marktxx
Although the C90 standard only mentions the use of 'signed int' and
'unsigned int' for bit-fields (use 'int' at your own risk) and C99
adds _Bool.
It seems that most compilers create the size of the bit-field object
from the size used to specify the field.
Could this be considered a defacto standard now (at least for 8 bit
sized bit-fields)?
Any recent compilers not allowing this?
struct
{
unsigned char x:4;
unsigned char y:4;
} nibs;
struct
{
unsigned int x:4;
unsigned int y:4;
} nibs;
see
http://www.keil.com/support/docs/928.htm
It refers the OP to the book
"The C Programming Language" by Kernighan & Ritchie but this book
doesn't mention using unsigned char in bit-fields.
[Soapbox]
Wouldn't it had more sense for the compiler folks to just add up the
specified number bits and use the smallest integer type that would fit
so code could follow the standard?
Obviously programmers want to use bit-field objects that may be
smaller or larger than standard integer size shouldn't the standard
support that.
(I know that one can always use masking and shifting but that isn't my
question.)
[end soapbox]
'unsigned int' for bit-fields (use 'int' at your own risk) and C99
adds _Bool.
It seems that most compilers create the size of the bit-field object
from the size used to specify the field.
Could this be considered a defacto standard now (at least for 8 bit
sized bit-fields)?
Any recent compilers not allowing this?
struct
{
unsigned char x:4;
unsigned char y:4;
} nibs;
struct
{
unsigned int x:4;
unsigned int y:4;
} nibs;
see
http://www.keil.com/support/docs/928.htm
It refers the OP to the book
"The C Programming Language" by Kernighan & Ritchie but this book
doesn't mention using unsigned char in bit-fields.
[Soapbox]
Wouldn't it had more sense for the compiler folks to just add up the
specified number bits and use the smallest integer type that would fit
so code could follow the standard?
Obviously programmers want to use bit-field objects that may be
smaller or larger than standard integer size shouldn't the standard
support that.
(I know that one can always use masking and shifting but that isn't my
question.)
[end soapbox]