Page 1 of 1

possible signed vs unsigned issue

Posted: Thu Jun 03, 2021 5:28 am
by voidstar
I'm sure this is an error on my part or some misunderstanding about K&R C ......

I was passing a constant -20 to a function, where the 2nd parameter is signed char. I evaluated that signed char with "< 1" (less than 1).




void initialize_challenges(unsigned char index, signed char initial_x, signed char initial_y) {
...
if (initial_x < 1) //< Could NOT get this logic to evaluate as TRUE...
{
// reverse the icon since coming from left side of screen
}
else {
// regular stuff
}
}

void main() {
....
initialize_challenges(challenges_count, -20, 14);
....
}



I tried doing explicit casts on the constants, but that didn't work either. I ended up just having to pass another argument to the function called, REVERSE and pass it as TRUE/FALSE. But still not understanding why the original code wasn't working.

Re: possible signed vs unsigned issue

Posted: Sun Jun 06, 2021 7:02 pm
by dom
Looks like that was codegen bug, I've raised a GitHub issue here: https://github.com/z88dk/z88dk/issues/1805 and also submitted a fix for it so it should be available in the next nightly.

Thanks for the report.