Hi All, I don't believe this is actually a bug, but can anybody explain why this code works correctly
void func(int v1, int v2){ unsigned char code tbl[] = {'a', 'b', 'c', 'd', 0, '1', '2', '3', '4'}; signed char xdata diff = v1 - v2; if (diff >= -4 && diff <= 4) printf("%c\n", tbl[diff + 4]); }
void func(int v1, int v2){ unsigned char code tbl[] = {'a', 'b', 'c', 'd', 0, '1', '2', '3', '4'}; int xdata diff = v1 - v2; if (diff >= -4 && diff <= 4) printf("%c\n", tbl[diff + 4]); }
stefan, You are right. I have used U8, S8 and thus not had a char or int that was not prefaced by (un)signed for ages. Memory corrected, thanks. Trevelig veckohaelg Erik
I know what a "character" is, but I've always wondered what a negative signed char would be. -A? Is -A less than -Q in lex order, or greater than? And then there's the combinations. Is "-w-o-r-d" the same as "word", while "-t-h-e" is the same as "-the"? Do signed chars cancel out when adjacent in strings, making "bokeper" out of "bo-ok-ke-eper"? 8-bit integers are much easier to understand.
"I know what a "character" is, but I've always wondered what a negative signed char would be." A depressed one? I wonder whether someone from Keil would like to comment on the original thread topic?
I wonder whether someone from Keil would like to comment on the original thread topic? This appears to be a code generation issue with the compiler. I submitted it to engineering and they are working on it. Jon
I know what a "character" is, but I've always wondered what a negative signed char would be. Just a negative number in a small datatype (8-byte in C51, may be larger elsewhere). It's usually a good idea to think of all actual characters (i.e. the things written in 'a' notation) as unsgined values. That's what the C library does, too: see the description of <ctype.h> as an example.
"This appears to be a code generation issue with the compiler. I submitted it to engineering and they are working on it." Jon, thanks. Could you post the conclusion when engineering are done, in particular which compiler versions are affected?
This problem has been corrected and will be included in the next C51 compiler update (which will be on the web site by November 5). Jon
This problem has been corrected and will be included in the next C51 compiler update (which will be on the web site by November 5). Will I be able to use this update with version 7.01 of the compiler?
C51 V7.50 is available on the web at: http://www.keil.com/update/sw/c51/7.50 Jon