Path: utzoo!dciem!nrcaer!sce!asterix!jimp From: jimp@asterix.UUCP (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: bitfields considered harmful? Message-ID: <6047@asterix.UUCP> Date: 4 May 89 16:26:11 GMT References: <1473@uwbull.uwbln.UUCP> <705@cf-cm.UUCP> Reply-To: jimp@cognos.UUCP (Jim Patterson) Distribution: comp Organization: Cognos Inc., Ottawa, Canada Lines: 23 In article <705@cf-cm.UUCP> sme@computing-maths.cardiff.ac.uk (Simon Elliott) writes: >In article <1473@uwbull.uwbln.UUCP>, ckl@uwbln.UUCP (Christoph Kuenkel) writes: >> We have some software using C bitfields like in >> I like them cause they save space ... >Well, you may be right about readability, but I don't think you'll find that >you've saved much space in your program. Oh, you might save it in the >source, but the same shifting and masking is going on under the hood. This may be so if the computer doesn't have bitfield operations, but many (e.g. VAX, MC68020, 80286) have instructions that implement bitfields directly. Even single-bit test and set instructions are worthwhile as bit-flags are quite common. These instructions can result in considerably shorter code sequences as they deal with small numbers (usually in the range 0 to 31, i.e. 5 bits) instead of large 32-bit masks. Most compilers aren't smart enough to "optimize" a series of ands/ors and shifts into bitfield access. -- Jim Patterson Cognos Incorporated UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707 PHONE:(613)738-1440 3755 Riverside Drive Ottawa, Ont K1G 3Z4