"address" of a bitfield

John Hascall hascall at atanasoff.cs.iastate.edu
Wed Jul 19 01:22:52 AEST 1989


In article <utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>In article <@blake.acs.washington.edu> wiml at blake.UUCP (William Lewis) writes:
 
>>  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...
>>    Does anyone know of an even semi-portable way to do this? ...
 
>Can't be done -- the packing of bitfields into words/chars/whatever is
>highly machine-specific (even the order, left-to-right or right-to-left,
>varies) and the information is not available to the program.

    But it is available to the compiler!  Which is what I think Mr. Lewis
    was thinking of--that it be handled like the "sizeof" operator.

    It seems like useful information, but perhaps separate operators would
    be more convenient:

	 bit_sizeof(foo)
	 bit_offsetof(foo)
	 bit_baseof(foo)

    John Hascall  /  ISU Comp Center  /  Ames IA



More information about the Comp.lang.c mailing list