bitfields: how to cast (int) into a bit field?

Wayne Throop throopw at dg_rtp.UUCP
Sun Jan 4 04:55:39 AEST 1987


> idallen at watmath.UUCP
> How does one cast an integer into, say, a 6-bit bit field in such a
> manner that LINT won't complain "conversion may lose accuracy"?

Since bit fields can only be uttered as structure members, and since
only the trivial cast is available on structures, it is simply not
possible to utter a cast of an int into a 6-bit field.  There ARE ways
of supressing lint's warnings, of course.  One way is to cause the
preprocessor to include the offending assignment only when compiling and
not when typechecking.

> How does one create a typedef for a bit field, such that one might use
> it to perform the above cast?

Again, it is simply not possible to have a "bit-field type" in C.

--
The negative judgment is the peak of mentality.
                                --- Alfred North Whitehead
-- 
Wayne Throop      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.unix.wizards mailing list