Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!samsung!zaphod.mps.ohio-state.edu!uwm.edu!csd4.csd.uwm.edu!kam2 From: kam2@csd4.csd.uwm.edu (Keith A Mcmillan) Newsgroups: comp.lang.c Subject: Re: How portable are bitfields? Summary: all over the map Keywords: bitfields, #define Message-ID: <6227@uwm.edu> Date: 10 Sep 90 18:22:55 GMT References: <508@mtndew.Tustin.CA.US> Sender: news@uwm.edu Reply-To: kam2@csd4.csd.uwm.edu (Keith A Mcmillan) Distribution: usa Organization: University of Wisconsin-Milwaukee Lines: 36 In article <508@mtndew.Tustin.CA.US> friedl@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