I've read what the others said, and if the following was the case you'd expect it to have been said. This is somewhat implicit in at least one reply. As =A0=A0=A0=A0=A0=A0 foo+bar is capable of overflowing an 8 bit word, then at least bat needs to be int for safety. Once you start going 'int char char'=A0 you can imagine the compiler wanting to have consistent type, even though obviously unnecessary. Using logical operators and two 8 bit words, which cannot ever produce a non char result doesn't trigger the action. =A0 Russell On 30 March 2010 11:06, Bob Blick wrote: > > I'm using HiTech C on a 16F688 and notice a promotion I didn't think > should happen. Here's a little example. "Something" is unimportant but > included for context. > > unsigned char foo; > unsigned char bar; > unsigned char bat; > > if(bat=3D=3Dfoo+bar) > =A0 =A0Something(); > > The compiler promotes the unsigned chars to integers, does the add and > does the comparison. In the past I always thought HiTech used the native > data size unless there was a reason not to (although I can't seem to > find reference to that right now). And since everything, including the > left operator "bat" are unsigned chars, I assumed (incorrectly) that all > the math and comparisons would be 8 bit. Optimization is set as high as > it goes, and this is the paid version of the compiler. > > Manually casting does fix it: > > if(bat=3D=3D((unsigned char)(foo+bar))) > =A0 =A0Something(); > > And something like this also does efficient 8 bit math: > > if(!(bat^(foo&bar))) > > but this doesn't: > > if(!(bat^(foo+bar))) > > so it isn't that the comparison with a constant (the implied "0") is the > reason for the promotion, it's the use of addition. > > I haven't been able to find any reference that covers these cases in > 8-bit implementations of "C" and my HiTech manual hasn't given me > anything either. > > Any idea where I can look for definitive rules on this? > > Thanks, > > Bob > > > > -- > http://www.fastmail.fm - Send your email first class > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist