2 !!DESCRIPTION!! equality problem
4 !!LICENCE!! Public Domain
8 Different results, depending on whether constant is on left or right side.
10 The optimizer sometimes makes code that executes the right-side expression
11 as eight bits; but then, tests it against the left-side zero as 16 bits.
12 The high-byte is garbage; therefore, that test might, or might not, work.
13 It depends on the platform and the amount of optimization.
15 http://www.cc65.org/mailarchive/2014-10/11680.html
16 http://www.cc65.org/mailarchive/2014-10/11682.html
17 http://www.cc65.org/mailarchive/2014-10/11683.html
22 static unsigned char fails = 4;
23 static unsigned char bad[3], good[3];
27 unsigned char joy_state = 0x7e;
30 /* NOTE: It fails in only the printf() statements, the other stuff
32 printf("bad: %u, ", 0 == (joy_state & 1) );
33 printf("good: %u\n", (joy_state & 1) == 0 );
35 sprintf(bad, "%u", 0 == (joy_state & 1) );
36 sprintf(good, "%u", (joy_state & 1) == 0 );
38 printf("bad: %u, ", bad[0] - '0' );
39 printf("good: %u\n", good[0] - '0' );
41 fails -= bad[0] - '0';
42 fails -= good[0] - '0';
44 if (0 == (joy_state & 1)) fails--;
45 if ((joy_state & 1) == 0) fails--;
47 printf("failures: %u\n", fails );
49 /* The above printf() returns a value with a zero high-byte.
50 ** Therefore, the next (broken) statement works (by accident).
52 a = 0 == (joy_state & 1);
53 b = (joy_state & 1) == 0;
55 printf("a: %u, ", a );
56 printf("b: %u\n", b );