> Thanks to all who responded to this - it works fine in Hitech C. One > observation, though, hitech is very code-inefficient at doing maths on > bitfields longer that one bit, so you can often save a lot of code by > copying the bitfield to a temporary char, doing the maths, then > copying it back. I was messing around with bits and bitfields last night, trying to squeeze out a few more code words. Because bit types aren't initialised, I had 16 of them, each getting a bcf instruction. Ah, I thought. Put them in a union with an int or a couple of chars and it will only take a couple of instructions to clear them. No. Can't do that. You can't have bit types within a structure. You can define them as ANSI style bitfields (which are on byte boundaries in HiTech C), unionise them and clear them with a couple of instructions but then when you try to use them, unless it is a single bit operation, the code bloats out to use shifts and masks. By single bit operation, I mean that MyBit = 0 compiles to bcf MyBit, but MyBit = MyOtherBit compiles to get the byte, mask the byte, test the result, get the byte, or in the mask, put the byte back. That's regardless of where the bits are in the byte and with having all bitfields one bit long. You can get the best of both worlds if you put your bits at a specified address in the same way you do for registers. static unsigned char bits1 @ 0x23; static bit MyBit @(unsigned)&bits1*8+0; static bit MyOtherBit @(unsigned)&bits1*8+1; etc. That way bits1 = 0 compiles to clrf 0x23 and MyBit = MyOtherBit compiles to bcf, btfsc, bsf. The address I used is the address that PICC was putting them anyway. Steve. ====================================================== Steve Baldwin Electronic Product Design TLA Microsystems Ltd Microcontroller Specialists PO Box 15-680, New Lynn http://www.tla.co.nz Auckland, New Zealand ph +64 9 820-2221 email: steveb@tla.co.nz fax +64 9 820-1929 ====================================================== -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics