How portable are bitfields?

Keith A Mcmillan kam2 at csd4.csd.uwm.edu
Tue Sep 11 04:22:55 AEST 1990


In article <508 at mtndew.Tustin.CA.US> friedl at mtndew.Tustin.CA.US (Steve Friedl) writes:
>Hiho folks,
>
>     Do people porting software to lots of different machines
>generally avoid bitfields?
>
Yes.  Alternatively, you can define the structure of the fields inside of 
a #ifdef for the machine type.  This may require you to do a bit of work
to determine what order the bits go in, but it saves re-writing code or
mucking up your code with #ifdefs.  a brief example is given below:

#define VAX

#ifdef VAX
...
int one:1;
int two:1;
...
#elseif
...
int sixteen:1;
int fifteen:1;
...
int one:1;
...
#endif

That way, your structure always puts the bits in the same order in the word,
regardless of what machine, you are on.  All you have to do is define VAX
(or whatever) or not.  This can be done on the command line to CC with the -D
option.

>Steve's bright idea #44: COBOL interface library for X Windows
Great! After that, how about Algol? ;-)

Keith



More information about the Comp.lang.c mailing list