"address" of a bitfield

Warren Tucker wht at tridom.uucp
Tue Jul 18 01:31:22 AEST 1989


In article <2840 at blake.acs.washington.edu>, wiml at blake.acs.washington.edu (William Lewis) writes:
> 
>    BitFAddr(thing.field, start, offset, width);
>   which would assign to 'start' the (char *) pointing to the start of the
> bitfield, to 'offset' the number of bits into the char the bitfield starts,
> and to 'width' the width of the bitfield in bits. Using this info, I
> could read & write the bitfield using '<<' and the bitwise operators.
>
Completely non-portable, but that may be ok for you (the actual 
format of bit fields are are left to the compiler writer's whim).
Try passing the address of the structure to a function that knows which
field to manipulate.
The best way to be portable would be to scrap bitfields alllll tooogether
and use #defines for bit masks.



More information about the Comp.lang.c mailing list