Re: [gtk-list] Re: sources



[bitfields]
>It's regular C. It means that this should only take one bit in memory. When
>you have lots of field in a structure, that should only take two value
>(boolean), then instead of using lots of byte, you can pack all the fields by
>defining the size in bits.

Except the compiler is perfectly at liberty *not* to do this and use, say, an 
int for each field.

Bit-fields would be mind-bogglingly useful if it were actually defined in the 
C standard how they were packed. But they're not. For example:

	union {
		unsigned char as_char;
		struct {
			red: 3;
			blue: 2;
			green: 3;
		} as_rgb;
	} RGB

...would be really useful for 8-bit colour cubes, if it not for the fact that 
sizeof(RGB) can vary from 1 to 12 depending on what compiler you use.

Does anyone know what gcc does?

-- 
+- David Given ---------------McQ-+ A three-legged dog walks into a saloon
|  Work: dg@tao.co.uk             | in the Old West. He sidles up to the bar
|  Play: dgiven@iname.com         | and announces: "I'm looking for the man
+- http://wired.st-and.ac.uk/~dg -+ who shot my paw."                        




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]