Re: [cc65] ca65: Global scope specifier required in "constant expressions"??

From: Ullrich von Bassewitz <>
Date: 2011-07-05 10:43:06

On Mon, Jul 04, 2011 at 06:45:54PM -0700, Agent Friday wrote:
> I've been getting the "constant expression expected" error where I
> don't think I should be.  I isolated the issue to the conditional
> assembly directive being inside a .proc scope vs. being in global
> scope.

Thanks for reminding me. This should definitely go into the FAQ, I'm answering
this (or similar issues) at least once per months.

The reason why this happens is that there may be a later symbol definition in
local scope:

    .PROC test_irq
       ; code here
    USE_JOYPORT = 0     ; Symbol in local scope with identical name!

You would expect the assembler to use the local symbol, wouldn't you? But when
the definition is reached, the .IF condition has already been decided. This is
the reason why you need to tell the assembler which symbol you want.

There are cases where it doesn't matter, because evaluation can be delayed:

    .PROC test_irq
      lda #USE_JOYPORT
    USE_JOYPORT = 0     ; Symbol in local scope with identical name!

Since the later symbol doesn't change the size of the code, the assembler can
delay expression evaluation until the end of the local scope is reached. But
this is not the case with .IF.



Ullrich von Bassewitz                        
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Jul 5 10:43:13 2011

This archive was generated by hypermail 2.1.8 : 2011-07-05 10:43:17 CEST