How portable are bitfields?

John D. Mitchell c164-bd at falstaff.uucp
Sun Sep 9 22:47:44 AEST 1990


In article <508 at mtndew.Tustin.CA.US> friedl at mtndew.Tustin.CA.US (Steve Friedl) writes:
>Hiho folks,
>
>     In our Allegedly Portable Software we have run into some
>code that could naturally use bitfields to nice advantage (in
>readability, at least), and I wonder how reasonably I can rely on
>compilers to support them properly.  I generally know the
>portability concerns for bitfields when they are supported
>properly by the compiler, but I seem to notice that bugs related
>to bitfields seem to have had problems for as long as I can
>remember (since the early eighties).
[stuff deleted]

I bow to those porting gurus out there but my experience says that
if you're using the bit-fields to do strange, miraculous fiddling
of hardware dependant things then no it most likely will not port
to other machines.  If you are doing something where your bit-fields
adhere to the ANSI rules that be and only do things such as setting
and testing the field and don't use more than 16-bits (i.e. minimum
sizeof(int)) then it should port very well.  My inkling is that
if you're code's portability is that big of an issue don't do it!

Good luck,
	John Mitchell

#include <std.disclaimer>



More information about the Comp.lang.c mailing list