Re: [cc65] question about assignment statement

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2006-01-20 20:36:47
On Fri, Jan 20, 2006 at 01:29:08PM -0600, PH wrote:
> So even though a is declared as an unsigned char, constants like 9 are
> actually 16-bit?  Is there any way to force them to 8-bit?

In C, all numeric constants that are in integer range are of type int. Not
even this, but character constants are also integers. On many platforms, C and
C++ compilers compile the following code differently, because a character
constant is of type int in C and of type char in C++:
                       
        #include <stdio.h>  
        #include <stdlib.h>

        int main (void)
        {
            printf ("%u\n", (unsigned) sizeof ('A'));
            return EXIT_SUCCESS;
        }

cc65 will output "2", because 'A' is an integer constant, and sizeof(int) == 2.

You can cast numbers to chars, but this doesn't really help, since in
expressions, characters are immediately promoted to integers. The cc65
optimizer will fix most of these cases for you.

> Would it be alright if I email you my code so you can see if you get the
> same error when you compile it?

Yes, of course. But if the code base is large, please remove anything that is
not really necessary to compile the code. Please do also state, which version
you're using.

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 Jan 20 20:37:01 2006

This archive was generated by hypermail 2.1.8 : 2006-01-20 20:37:03 CET