This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

CA65: Detect if an identifier exists using result of .ident?

CA65: Detect if an identifier exists using result of .ident?
by on (#169307)
I'm working on my own set of macros to help save time in my next project, and one thing I was searching for was detecting if an identifier already exists like this:

Code:

.ifdef .ident(.concat(.string(arg), "_my_useful_suffix"))   ;This does not work, it wants an actual identifier here, even if using what .ident returns DIRECTLY would assemble
.endif



I'm able to work around this, but if this could work it'd help me make these macros that much more useful. I was surprised it does not work. Mainly because .ident can be used to generate code that references an existing symbol---apparently you just can't TEST for existence.
Re: CA65: Detect if an identifier exists using result of .id
by on (#169319)
Well that code does work if the symbol you're testing for is defined in the same module.

Maybe try .ifconst? Edit: maybe not. I don't think .ifconst will work.
Re: CA65: Detect if an identifier exists using result of .id
by on (#169328)
I'm pretty sure I have done this before... Will have to check my sources.

EDIT: Yes, I have this in one of my files, which works correctly:
Code:
.ifdef Assembler::.ident(.sprintf("ProgramRAMPage%02xOffset", _ProgramRAMPage))

The main difference I see is that my symbol is scoped, I don't know if that makes a difference in this case.
Re: CA65: Detect if an identifier exists using result of .id
by on (#169355)
The first thing to try would be to update ca65 to the latest version. Also post the error message that you're getting.
Re: CA65: Detect if an identifier exists using result of .id
by on (#169543)
It may be related to the symbol in question being defined in a different object file (as suggested above). Though, I am using .global and including the symbol at the top of my module, so I'd think for the purposes of assembly and producing a symbol in an object file to be linked later on, this should work. I tested what I'm trying to do, in an isolated case like this:

Code:

.macro test arg

    .ifdef .ident(.concat(.string(arg), "_lo"))
        .out "Hello"
    .else
        .out "Nope"
    .endif

.endmacro
...


    my_test_symbol = 1
    my_test_symbol_lo = 1

    test my_test_symbol



This works just fine. So...not yet quite sure what's going on. I had already found a workaround which may actually be better than what I wanted to use this for, but...I'm curious.