From: Christian Groessler (cpg_at_aladdin.de)
Date: 2003-01-02 22:20:52
Hi, On 01/01/2003 10:17:26 PM CET Ullrich von Bassewitz wrote: > >Yes it should. The C standard calls this "int promotion". Expressions are >always evaluated with type int, never using smaller data types. For cc65, int >promotion is done when loading the character into the primary register (a/x). >The original compiler had signed characters, which meant that sign extension >was quite expensive, and doing it when loading saved some code. > >The effect of having sign extension when loading is that the compiler expects >that a char data type is always extended to an int. Using > > unsigned char count = joy_count (); > >is no problem when joy_count() does not set the X register, but > > unsigned count = joy_count (); > >is, because the compiler doesn't do the conversion from char to int, so the >high byte is wrong. I think this is something which should be documented (sorry, if it already is.). It's quite vital information for people writing subroutines in assembler. If I understand it correctly the compiler assumes return values from functions to be already "int promoted". This is quite different from the (obvious?) assumption that a function returning char will only return a char. >If you are archiving your mail, you may want to have a look at our private >mail exchange starting "Sat, 25 Mar 2000 11:56:16 +0100", where I explained >exactly the same thing to you:-) I knew from that discussion somewhere back in my brain that functions should return AX, but I had forgotten the reason. regards, chris ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-01-02 22:22:38 CET