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

From: Ullrich von Bassewitz <>
Date: 2011-05-09 19:05:00
On Mon, May 09, 2011 at 03:58:35AM +0900, Yutaka Amanai wrote:
> Probably I found a solution by myself. For .proc labels, .sizeof()
> seems to return the size of the whole content (until .endproc). So,
> I can define large data on multiple lines enclosing it with .proc
> and .endproc. It is data, not "procedure", but the method seems ok
> for my purpose.

It is ok in general. This is how .proc is intended to be used.

Regarding the working of .sizeof: For labels it uses the data on the line with
the label. Choosing another definition would be quite difficult. How many
bytes should be counted? Up to the next label? What if the next label is a
local one, a .PROC, or one defined with := ?

For .PROC or .STRUCT (anything that encloses something) it is the size of the
whole thing (for .PROC only data in the segment counts that is active when
.PROC starts).

> 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".

The reason is the local scope. ca65 doesn't know if a local symbol STR will
follow when it encounters the first line of myproc. For example, myproc could
look like

        STR:    .byte   "str"
        .proc   myproc
                lda     STR,x
                lda     #.sizeof(STR)
        STR:    .res    256

in which case .sizeof(STR) would be 256 instead of 3. If you want to
explicitly address the symbol STR in global scope, just use ::STR.



Ullrich von Bassewitz                        
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon May 9 19:05:09 2011

This archive was generated by hypermail 2.1.8 : 2011-05-09 19:05:12 CEST