bit fields in C
mjs at rabbit.UUCP
mjs at rabbit.UUCP
Sun Aug 14 01:13:28 AEST 1983
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
More information about the Comp.lang.c
mailing list