[comp.unix.wizards] bitfields: how to cast

idallen@watmath.UUCP (12/22/86)

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"?

How does one create a typedef for a bit field, such that one might use
it to perform the above cast?
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo

throopw@dg_rtp.UUCP (Wayne Throop) (01/03/87)

> idallen@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