Do you use bit fields?

lcc.barry at UCLA-LOCUS.ARPA lcc.barry at UCLA-LOCUS.ARPA
Wed Sep 19 03:30:59 AEST 1984


From:            Barry Gold <lcc.barry at UCLA-LOCUS.ARPA>

I suspect a lot of people don't use bit fields because, like me, they've been
bitten by compilers that turn out awful or even WRONG code for them.  The
weirdest I ever saw, though, was the Oracle C compiler for the 370, delivered to
sdcrdcf's 4331 in September 1982.  

If you tried initializing an auto structure (prohibited in V7), it wouldn't
produce any diagnostics, but would put the generated data into the TEXT
section right after the subroutine entry code.  This resulted in some
INTERESTING program behavior--especially the time the data happened to work
out to valid instructions.

But, if the structure was defined with bitfields, it would initialize it
correctly--by generating the code to initialize each bitfield individually.
This was neither fast nor compact, but WAS correct.

It also had a code generation problem which is fairly common in naive compilers
(I've seen it in JOVIAL, too).  Every access to a bitfield was treated as 
though you were going to do arithmetic on it or assign it to an int; it would
be loaded into a register, masked off, and shifted into the low order bit.
THIS, even if you only wanted to test a one bit field for zero/non-zero
(there's an instruction to do that on the 370).  EVEN if the one bit field was
in the sign bit!

(It could be worse:  the JOVIAL I saw masked off bitfields by shifting them
to the high order end of the word, then shifting back to the low order end.
Never heard of the AND instruction, I guess.)

barry gold



More information about the Comp.lang.c mailing list