Author Topic: single line macro with valid empty definition needed  (Read 10345 times)

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
single line macro with valid empty definition needed
« on: June 27, 2014, 12:48:16 PM »
Hello!

The following macro is part of my real macro, but I reduced it to the problem.

Code: [Select]

%macro show_problem 0

  %define %%str

  %xdefine %%str %%str %+ 0x0

%endmacro


It gives me this error:
fatal: (show_problem:3) No lvalue found on pasting

The macro works well if I initialize %%str, but I don't need any initialization value. Is it possible to initialize it with something that do not expand? Or something that would only expand to a space character? I feel, if I had tried thousand things but nothing worked.

A work around is not the problem, but maybe a workaround can be avoided.

Thank you
Please comment your code! It helps to help you.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: single line macro with valid empty definition needed
« Reply #1 on: June 27, 2014, 06:20:52 PM »
I don't know the answer to that one. I'm not a sophisticated macro user. I do use a macro with something defined "as nothing"...
Code: [Select]
%define ptr
%define offset
; some Masm/Tasm code
This causes "ptr" and "offset" to "vanish", as intended. So I'm not surprised your macro doesn't work. Obviously you intend something different... but I'm not sure what.

Best,
Frank


Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
Re: single line macro with valid empty definition needed
« Reply #2 on: June 27, 2014, 07:23:06 PM »

Code: [Select]
%xdefine %%str %%str %+ %%l,
this line builds a sequence like that one:  5,18,16,22,0,1,
but it only works if %%str is initialy defined with something.

btw: str is a bad name, because this sequence must be a token or a token sequence

db %%str  ; as string results in
db "5,18,16,22,0,1,0"

db %%str  ; as token sequence results in
db 5,18,16,22,0,1,0

Please comment your code! It helps to help you.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: single line macro with valid empty definition needed
« Reply #3 on: July 14, 2014, 09:07:55 AM »
That won't work because the concatenation operator (%+) requires a valid left-hand value (lvalue) to concatenate to. You could wrap the code in an %ifdef statement instead.

Code: [Select]
%ifdef %%str
   %xdefine %%str %%str %+ %%l,
%else
   %define %%str %%l,
%endif

About Bryant Keller
bkeller@about.me

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
Re: single line macro with valid empty definition needed
« Reply #4 on: July 15, 2014, 12:26:03 PM »
Thank you!

I'd hoped that there is an valid empty token, that acts like zero in arithmetic additions or as "" in string concatenation.

Maybe it will be implemented in one of the next versions of NASM?!
Please comment your code! It helps to help you.