Re: [cc65] char = int / 8

Date view Thread view Subject view

From: Groepaz (groepaz_at_gmx.net)
Date: 2003-10-03 21:22:00


On Friday 03 October 2003 20:54, MagerValp wrote:
> This little snippet:
>
>   void test(void) {
>     unsigned int i = 257;
>     unsigned char c;
>
>     c = i / 8;
>   }
>
> Generates this:
>
> ;
> ; unsigned int i = 257;
> ;
> 	lda     #$01
> 	sta     L0003
> 	sta     L0003+1
> ;
> ; c = i / 8;
> ;
> 	lda     L0003
> 	lsr     a
> 	lsr     a
> 	lsr     a
> 	sta     L0005
>
> Which isn't exactly what I expected. Explicit casts doesn't seem to
> help. Am I or the compiler wrong?

mmmh not 100% sure, but i think the compiler is correct here.... however,
this:

c=(((int)i)/8)

should result in what you expect.

gpz

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-10-03 21:27:10 CEST