problems with the C parser

Gary M. Samuelson garys at bunker.UUCP
Sat May 31 00:29:04 AEST 1986


In article <5072 at topaz.RUTGERS.EDU> brisco at topaz.UUCP writes:

>	typedef union {
>		int intfield;   /* change the record name - keyword */
>		struct bool{unsigned x[32]:1};
>		} newtype;

>	Can anyone else compile the above structure declaration?

No.  You didn't read far enough:
	"In all implementations, there are no arrays of fields"
	K&R, p. 197

I tried
	typedef union {
		int intfield;
		struct bool {int x:1; }bit[32];
		} newtype;

But each bit takes up an entire unsigned, so the size of the above
is 32 * sizeof (unsigned).

I think you will have to choose from masks, or making each bit a
separate field:
	typedef union {
		int intfield;
		struct	bool {
			unsigned
			x0:1,  x1:1,  x2:1,  x3:1,  x4:1,  x5:1,  x6:1,  x7:1,
			x8:1,  x9:1,  x10:1, x11:1, x12:1, x13:1, x14:1, x15:1,
			x16:1, x17:1, x18:1, x19:1, x20:1, x21:1, x22:1, x23:1,
			x24:1, x25:1, x26:1, x27:1, x28:1, x29:1, x30:1, x31:1;
		}
	} newtype;

Gary Samuelson



More information about the Comp.lang.c mailing list