Author Topic: Warning: dropping trailing empty parameter  (Read 16826 times)

Offline fullofbugs

  • Jr. Member
  • *
  • Posts: 9
Warning: dropping trailing empty parameter
« on: February 09, 2021, 04:01:37 AM »
I have a set of macros that combined have more than 16,000 lines. After updating NASM to 2.15 and recompiling my codes, I was greeted with thousands of "Warning: dropping trailing empty parameter in call to macro" warnings. I can disable this by turning off the "macro-params-legacy" warning, but it is not a good practice. So I wonder how to deal with this properly.

Considering a simple example,

Code: [Select]
%macro _AND 2-3.nolist
    AND  %1, %2
  %ifnempty %3
    AND %1, %3
  %endif
%endmacro

%macro _ANDOR 3-4.nolist
  _AND  %2, %3, %4
  OR    %1, %2
%endmacro

calling _ANDOR with three parameters leads to the above warning.

Code: [Select]
        _ANDOR EAX, EBX, ECX

At first, I thought that the newly introduced %, operator could suppress the warning. But changing the code to

Code: [Select]
%macro _ANDOR 3-4.nolist
  _AND  %2, %3 %, %4
  OR    %1, %2
%endmacro

led to a syntax error. For now, the only way that I can think about is to use conditions

Code: [Select]
%macro _ANDOR 3-4.nolist
  %ifempty %4
    _AND  %2, %3
  %else
    _AND  %2, %3, %4
  %endif
  OR    %1, %2
%endmacro

But this is error-prone, laborious, and ugly. So is there a simple way to avoid the warning?

BTW, I understand the point of adding this warning, but wonder when it was added, did anyone consider the above scenario? Because NASM allows macros to have greedy and range parameters, it seems to me that this is avoidable and NASM should provide a way to do it elegantly. Expanding the use of the %, operator seems a reasonable resolution to me.

Offline fullofbugs

  • Jr. Member
  • *
  • Posts: 9
Re: Warning: dropping trailing empty parameter
« Reply #1 on: February 09, 2021, 12:29:36 PM »
After further trying, this is the way to do it. It is quite decent actually.

Code: [Select]
%macro _ANDOR 3-4.nolist
  _AND  %2, %3 %, {%4}
  OR    %1, %2
%endmacro

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Warning: dropping trailing empty parameter
« Reply #2 on: February 09, 2021, 11:31:31 PM »
Excellent! Thank you.

Best,
Frank