[cc65] broken string arithmetic

From: MagerValp <MagerValp1cling.gu.se>
Date: 2004-07-13 17:13:52
This piece of broken code:

> void main(void) {
>   int len = 10;
>   unsigned char *str = "xxxxxxxxxxxxxxxxxxxx" + len - 20; // should be - len + 20
> 
>   puts(str);
> }

produces the following compilation error with 2.10.0:

> Unresolved external `L0000' referenced in:
>   test.s(43)

from test.s:

> .segment        "RODATA"
> 
> L0001:
>         .byte   $58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58,$58
>         .byte   $58,$58,$58,$58,$00

and then

> ;
> ; unsigned char *str = "xxxxxxxxxxxxxxxxxxxx" + len - 20;
> ;
>         ldy     #$01
>         jsr     ldaxysp
>         clc
>         adc     #<(L0000)
>         tay
>         txa
>         adc     #>(L0000)
>         tax
>         tya
>         sec
>         sbc     #$14
>         bcs     L0005
>         dex
> L0005:  jsr     pushax

The code's broken, and it worked fine once I fixed it, but I'd expect
an invalid pointer rather than a compilation error.

-- 
    ___          .     .  .         .       . +  .         .      o   
  _|___|_   +   .  +     .     +         .  Per Olofsson, arkadspelare
    o-o    .      .     .   o         +          MagerValp@cling.gu.se
     -       +            +    .     http://www.cling.gu.se/~cl3polof/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Jul 13 17:13:55 2004

This archive was generated by hypermail 2.1.8 : 2004-07-13 17:14:04 CEST