Re: [cc65] ca65: .sizeof() doesn't return correct values?

From: Marc 'BlackJack' Rintsch <marc1rintsch.de>
Date: 2011-05-09 09:30:29
Hi Yutaka,

> But still there is a strange behavior. I wrote a test code:
> 
>    STR:    .byte   "str"
>    .proc   myproc
>            lda     STR,x
>            lda     #.sizeof(STR)
>    .endproc
> 
> Giving ca65 this code, it causes error: "Size of `STR' is unknown".
> If you comment out the line "lda STR,x", ca65 doesn't cause any
> error and .sizeof() returns 3. And, it seems that there are some
> ways to suppress this error:
>    * removing the lines ".proc" and ".endproc"
>    * explicitly specify STR as "::STR" (global label)
> Is it related to scope?

I'd say yes.  There are two different labels called `STR`.  One global 
and one local to `myproc`.  Just look at the produced listing::

 000000r 1  73 74 72        STR:    .byte   "str"
 000003r 1                  .proc   myproc
 000003r 1  BD rr rr                lda     STR,x
 000006r 1  A9 03                   lda     #.sizeof(::STR)
 000008r 1                  .endproc
 000008r 1               

As you see the value of `myproc.STR` is not known.  The two bytes read 
``rr``, meaning the linker has to plug in the correct value at link 
time.

Ciao,
	Marc 'BlackJack' Rintsch
-- 
“I will not sell my kidney on eBay
 I will not sell my kidney on eBay
 I will not sell my kidney on eBay …”   -- Bart Simpson

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon May 9 09:47:27 2011

This archive was generated by hypermail 2.1.8 : 2011-05-09 09:47:31 CEST