Sometimes, cc65 expects functions to return (at least) 16 bits -- even when they are declared to return eight bits! _rand8 must put a zero into the X register before it returns.
@greg: Thanks for the clarification:-)
This is by the way not specific to cc65. It's quite common that compilers
presume all functions to return "at least" an (unsigned) int. This is to
simplify the implicit promotion to int for expressions as described by the
C spec.
After this, var contains 9003, which is no way possible. rand8 returns 119 in this case. This happens both with and without -O.
If I write it in two lines, "var = 180; var += rand8();" the result is correct.
Asm with -O:
The text was updated successfully, but these errors were encountered: