parnass@ihuxf.UUCP (08/12/83)
There have been some recent net submissions lamenting
compiler objections to the declaration of long bit fields.
According to "The C Programming Language" (page 137) by
Brian W. Kernighan and Dennis M. Ritchie:
"A field is a set of adjacent bits within a
single int.... Fields behave like small, unsigned
integers, and may participate in arithmetic
expressions just like other integers."
Robert S. Parnass
Bell Laboratories
Naperville, IL
ihnp4!ihuxf!parnassmjs@rabbit.UUCP (08/13/83)
Independent of what K&R says, real compilers may or may not adhere. On
many compilers, the program below prints: "sbit: -1; ubit: 1". Thus,
many real compilers do not compile C.
/*
** bits.c: determine signedness of signed and unsigned bit fields.
*/
struct sbit
{
int sbit : 1;
};
struct ubit
{
unsigned ubit : 1;
};
main()
{
struct sbit sbit;
struct ubit ubit;
sbit.sbit = 1;
ubit.ubit = 1;
printf("sbit: %d; ubit: %d\n", sbit.sbit, ubit.ubit);
exit(0);
}
--
Marty Shannon
UUCP: {alice,rabbit,research}!mjs
Phone: 201-582-3199