This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bug in the compiler??

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]);

}
and this doesn't?
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]);

}
Is this behaviour ANSI-compliant?

Cheers

Parents
  • 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.

Reply
  • 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.

Children