Re: [cc65] another bug?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2009-10-23 11:35:24
Hi!

On Fri, Oct 23, 2009 at 11:03:40AM +0300, Karri Kaksonen wrote:
> Anyway all my code is written this way. I obviously need to add
> --signed-chars to all my Makefiles.

I would suggest to check the code instead. Any compiler is free to choose
either, so code that makes assumptions about the signedness of chars is highly
non-portable.

cc65 uses unsigned chars, because operations with signed data generates much
more code and is slower. For chars, the problems is what the standard calls
"integer promotion". In short, this means that all arithmetic operations
operate on ints, even if all operands are chars. So the compiler needs to do
sign extension on operands. Which - in case of unsigned chars - means just
loading 0 for the high byte. But for signed chars, the sign of the char has to
be tested and either 0x00 or 0xFF needs to be loaded for the high byte.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Oct 23 11:38:21 2009

This archive was generated by hypermail 2.1.8 : 2009-10-23 11:38:23 CEST