possible signed vs unsigned issue

Bug reports (if you don't/won't have a Github account)
Post Reply
voidstar
New member
Posts: 6
Joined: Sun May 30, 2021 6:38 am

possible signed vs unsigned issue

Post 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.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: possible signed vs unsigned issue

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