The following listing shows that the ~ operation is expanded to a short when used in a conditional expression. Attached is code with the problem, and the workaround.
---- unsigned char g() { return 0x5a; } void p(unsigned char c) { volatile unsigned char tmp; tmp = c; } int main(int argc, char * argv[]) { unsigned char XOR = 0xa5; unsigned char tmp = 0; if (g() == ~XOR) p(tmp); tmp = ~XOR; if (g() == tmp) p(tmp); return 0; } ---- if (g() == ~XOR) ea: 0e 94 52 00 call 0xa4 ; 0xa4 <g> ee: 28 2f mov r18, r24 f0: 30 e0 ldi r19, 0x00 ; 0 f2: 8a 81 ldd r24, Y+2 ; 0x02 f4: 88 2f mov r24, r24 f6: 90 e0 ldi r25, 0x00 ; 0 f8: 80 95 com r24 fa: 90 95 com r25 fc: 28 17 cp r18, r24 fe: 39 07 cpc r19, r25 100: 19 f4 brne .+6 ; 0x108 <main+0x3a> p(tmp); 102: 89 81 ldd r24, Y+1 ; 0x01 104: 0e 94 5a 00 call 0xb4 ; 0xb4 <p> tmp = ~XOR; 108: 8a 81 ldd r24, Y+2 ; 0x02 10a: 80 95 com r24 10c: 89 83 std Y+1, r24 ; 0x01 if (g() == tmp) 10e: 0e 94 52 00 call 0xa4 ; 0xa4 <g> 112: 98 2f mov r25, r24 114: 89 81 ldd r24, Y+1 ; 0x01 116: 98 17 cp r25, r24 118: 19 f4 brne .+6 ; 0x120 <main+0x52> p(tmp); 11a: 89 81 ldd r24, Y+1 ; 0x01 11c: 0e 94 5a 00 call 0xb4 ; 0xb4 <p> -- Summary: [avr] conditional comparison uses short instead of char Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: najay at najay dot com GCC host triplet: x86 GCC target triplet: avr-*-* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40935