Hmmm... that works. Some other interesting points to note... Original, which failed... if (S2 >=3D (S2_MAX + S2_STEP)) S2 =3D S2_MIN; This disassembled to... 0B16 0E82 MOVLW 0x82 0B18 5DBF SUBWF 0xbf, W, BANKED 0B1A 0EFF MOVLW 0xff 0B1C 59C0 SUBWFB 0xc0, W, BANKED 0B1E E303 BNC 0xb26 ' ... With the type-casting done in the definition as you suggested, the =20 same statement disassembles to... 0B30 0E82 MOVLW 0x82 0B32 5DBF SUBWF 0xbf, W, BANKED 0B34 0E00 MOVLW 0 0B36 59C0 SUBWFB 0xc0, W, BANKED 0B38 E303 BNC 0xb40 ... Here, the calculation of 125+5 is still correct (130 =3D 0x82), but the =20 3rd instruction is different. I can see now what it's thinking here, that 125 will fit in a signed =20 byte, so it uses that. And if I change the statement to "if (S2 >=3D =20 130)", then it knows that a signed byte won't work, so it interprets =20 it as unsigned, and works correctly. But this is so not intuitive. =20 When the compiler does the math on the defines and comes up with 130, =20 it should know then that a signed byte won't work. I'm going to reserve space on this list now for a future rant on this, =20 when this bites me in a big way. I just know that's coming. Thanks, -Neil. Quoting Tamas Rudnai : > Have you tried with a modification like this: > > #define S2_MIN ( (unsigned) 90 ) > #define S2_MAX ( (unsigned) 125 ) > #define S2_STEP ( (unsigned) 5 ) > > Tamas > > > On 25 January 2012 01:09, PICdude wrote: > >> Quoting Mark Rages : >> >> > On Tue, Jan 24, 2012 at 4:27 PM, PICdude wrote: >> >> Hmmm... still tinkering with C18 and ran into this oddity... >> >> ... >> >> > >> > How is "S2" declared? If it is an int8_t (aka char) then 125+5 =3D >> > -126, which is always going to be less than S2_MIN, so S2 will remain >> > at 90. >> > >> >> "unsigned int", because the full range of values will be 0 to 350. >> >> >> >> >> -- >> http://www.piclist.com PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist >> > > > > -- > int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; > printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", > q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .