Mail Archives: djgpp/1999/05/27/14:00:56
fred AT genesis DOT demon DOT co DOT uk (Lawrence Kirby) writes:
> No type in C is guaranteed to occupy a specific amount of space in memory.
> What C guarantees is minimum ranges for specific types. Bit-fields
> act like specific width types but there are few guarantees about their
> storage. Why do you need this anyway? Such a requirement usually
> indicates a poor approach.
(I can't speak for the original questioner, but...)
Maybe to store a large array of integers each of which only requires
24 bits of range.
To do this, I'd probably keep a malloc'd array of unsigned characters, and
write a macro to take an index, extract [i*3] [i*3+1] and [i*3+2] and
shove them into a long using << and | operators.
What to do when CHAR_BIT != 8 is left as an excercise to the reader.
Bill, bit flippingly.
- Raw text -