I'm using NASM 0.98.39 (an old version) to assemble the following test source file:
%macro M 1
%ifdef A_%1_B
%error OK
%else
%error undef
%endif
%endm
%define A_foo_B
M foo
I want OK
because A_foo_B
is indeed a defined single-line macro. In NASM 2.13.02, it displays OK
, however in NASM 0.98.39 and NASM 0.99.06, it displays undef
. How can I make it work with NASM 0.98.39?
Please note that upgrading NASM is not an option for this project, and inlining the macros M
wouldn't scale, because there are thousands of macro callers, and some abstraction is needed.
FYI If I change it like this, it stops working in NASM 2.13.02 as well, with the error message `%ifdef' expects macro identifiers.`:
%macro MS 1
%ifdef %1
%error OK
%else
%error undef
%endif
%endm
%define A_foo_B
MS A_foo_B
Even more stranglely, these both display OK
(as expected) in all the above versions of NASM:
%macro MH 1
%ifdef %1_B
%error OK
%else
%error undef
%endif
%endm
%macro MT 1
%ifdef A_%1
%error OK
%else
%error undef
%endif
%endm
%define A_foo_B
MH A_foo
MT foo_B
This workaround of defining 2 macros works in all versions of NASM mentioned in the question:
%macro MT 1
%ifdef A_%1
%error OK
%else
%error undef
%endif
%endm
%macro MIND 1
MT %1_B
%endm
%define A_foo_B 1
MIND foo
This needs a major refactoring of existing NASM macros using %ifdef
though.