"address" of a bitfield

William Lewis wiml at blake.acs.washington.edu
Mon Jul 17 13:25:19 AEST 1989


   For the usual reasons, I have to pass the address of a variable to
a function. (The function needs to read, and possibly modify, any of a 
large number of variables of diverse types.)  Unfortunately, many of these
variables are bitfields, and, obviously, bitfields don't strictly *have*
an address. Ideally, there is a macro I could write to get something along
the lines of:
  
   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.
    Does anyone know of an even semi-portable way to do this? Or, if
there is no portable way, a way that works with Mark Williams C on
a MSDOS machine? 
    Otherwise, I have to assign all my bitfields (many of which are only
1 bit wide) to chars, and transcribe them back again after the function 
call, to get the same effect, but with lots of ugly gunk around it...

    --- phelliax
        "&(foo.fie.fo -> fum.ziz.clf[grot->thup])"



More information about the Comp.lang.c mailing list