Author Topic: %comment and %endcomment doesn't work  (Read 19301 times)

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
%comment and %endcomment doesn't work
« on: June 01, 2014, 08:00:24 AM »
Hello everybody!

I am new to nasm and this forum. My english is ... a shame, sorry.

My question is, why doesn't %comment and %endcomment work?
I use %if 0 ... %endif instead, but, maybe I missunderstand something with
%comment and %endcomment

I use the win32 NASM version 2.11.05 compiled on May 21 2014
and get the following errors:

empty.asm:2: error: unknown preprocessor directive `%comment'
empty.asm:2: error: label or instruction expected at start of line
empty.asm:3: error: unknown preprocessor directive `%endcomment'
empty.asm:3: error: label or instruction expected at start of line

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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: %comment and %endcomment doesn't work
« Reply #1 on: June 01, 2014, 08:36:05 AM »
Hi Gammac!

Good question. That's a fairly new macro command. To tell the truth, I thought, "there's no such thing". I don't know when it was added. But I can confirm that it's documented, and that it doesn't work. Use %if 0 as a workaround, I guess.

Best,
Frank


Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: %comment and %endcomment doesn't work
« Reply #2 on: July 14, 2014, 08:49:09 AM »
%comment/endcomment was added quite some time ago, iirc by Keith. It was later taken out around the same time that the code for recursive macros was removed, not sure why though. It's been gone for quite some time and I don't think anyone has really noticed, till now. It probably should just be removed from the documentation. It was a good idea, though not sure it's worth reimplementing.

About Bryant Keller
bkeller@about.me

Offline Logman

  • Jr. Member
  • *
  • Posts: 16
  • Country: us
Re: %comment and %endcomment doesn't work
« Reply #3 on: July 27, 2015, 02:23:18 AM »
Since programmers still read this post, here's my two cents:

I just use two macros and either put them in my current program or a separate macro include file.

Code: [Select]
;----------------------------------------------------------------------
; _COMMENT (no parameters)
; _ENDCOMMENT (no parameters)
; PURPOSE: Provide multi-line comment capability
; USAGE: _COMMENT
;          statements commented out
;        _ENDCOMMENT
;----------------------------------------------------------------------
%imacro _COMMENT 0
  %push COMMENT         ; Push context
  %ifndef __COMMENT     ; Check that any previous COMMENT includes
    %define __COMMENT   ; a closing ENDCOMMENT directive
    jmp %$endcomment    ; Skip over all statements until ENDCOMMENT
  %else
    %error "_ENDCOMMENT missing after previous COMMENT directive!"
  %endif
%endmacro

%imacro _ENDCOMMENT 0
  %ifctx COMMENT         ; Verify context
    %$endcomment:        ; Jump here from COMMENT macro
    %undef __COMMENT     ; Undefine __COMMENT
    %pop COMMENT         ; Remove context
  %else
    %error "Missing _COMMENT directive before _ENDCOMMENT!"
  %endif
%endmacro

I use the _comment/_endcomment to comment-out parts of code I'm testing. That way I don't have to remove the code or use semi-colons to do the same job.

Logman
« Last Edit: July 28, 2015, 02:28:31 PM by Logman »

Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
Re: %comment and %endcomment doesn't work
« Reply #4 on: July 28, 2015, 04:59:00 PM »
Hi Logman,

   The appropriate way is to use
Code: [Select]
%if 0instead of
Code: [Select]
jmp %$endcomment
and

Code: [Select]
%endifinstead of
Code: [Select]
%$endcomment:
This way, you can really have any text in the block not just valid assembler mnemonics.
Also the code you comment won't be part of the output file (executable).

EDIT : I realized that %if 0 & %endif cannot be accomodated in your macro .
so I think I am just going to say that %if 0 , %endif can be a better way.
« Last Edit: July 28, 2015, 05:30:03 PM by Mathi »

Offline P3rry

  • New Member
  • Posts: 1
Re: %comment and %endcomment doesn't work
« Reply #5 on: February 29, 2016, 02:57:09 PM »
%comment/endcomment was added quite some time ago, iirc by Keith. It was later taken out around the same time that the code for recursive macros was removed, not sure why though. It's been gone for quite some time and I don't think anyone has really noticed, till now. It probably should just be removed from the documentation. It was a good idea, though not sure it's worth reimplementing.

Oh so it's been taken out, so that's why it doesn't work. It should be taken out of the documentation then to avoid confusion. Can Keith put %comment back in in the future?