unsigned char ttt[] = {0xff, 1};
unsigned char test(void)
{
unsigned char a, i;
// a = 0; /* uncomment this line to generate correct
code */
for (i = 0; i < sizeof(ttt); i++) {
a |= ttt[i];
}
return a;
}
The return value is 1, but is should be 0xff.
If the variable a is initialized, the result is correct.
This is a minimized code from the regression test
bug-971834.c.
$sdcc --version
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.5.6 #4244 (Jun 24 2006) (MINGW32)
sdcc -mpic16 -pp18f452 t.c
Borut
Not really helpful for fixing this, but maybe interesting to the readers:
unsigned char is the only type for which such a bug can exist. If the variable a was of any type other than unsigned char, the |= on the uninitialized value would be undefined behaviour. For unsigned char though, it's unspecified behaviour instead.
Philipp