volatile uint16_t r; unsigned char poly = 0x07; unsigned char c = 0; r = (c << 8) ^ poly;
When the code is compiled with gcc on Linux,
When the same code is compiled by Microchip C18,
If I change it to:
volatile uint16_t r; uint16_t poly = 0x07; uint16_t c = 0; r = (c << 8) ^ poly;
7 in C18, too.
There is a section about integer promotion in the C18 manual, but I don't think it has something to do with my question. Anyway, here it is:
ISO mandates that all arithmetic be performed at int precision or greater. By default, MPLAB C18 will perform arithmetic at the size of the largest operand, even if both operands are smaller than an int. The ISO mandated behavior can be instated via the -Oi command-line option.