Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

COMMENT/ENDCOMMENT doesn't work within a SWITCH statement

Apr
394
13
TCC (x64) Version 31.00 Build 10 [31.00.10]
Microsoft Windows 11 Home (21H2) [10.0.22000.2482]

I stumbled on this when debugging a SWITCH statement and I wanted to comment out one of the CASE parts for testing. If you comment out a CASE by using REM at the start of each line it works as expected and it's as if that CASE doesn't exist within the SWITCH when executed. However, if you surround the CASE with a COMMENT/ENDCOMMENT it isn't handled by the SWITCH processing and an error occurs.

COMMENT/ENDCOMMENT has been around since v17 and I've only just noticed this, so I don't consider it urgently needs a fix, and if it's a complex fix or one that might impact performance it would be acceptable (at least to me) to see the documentation updated to say you can't use it within a SWITCH statement (the help already mentions it can't be included in command groups).

Here's a short batch file which demonstrates the problem:

Code:
c:\test>type test.btm
@echo off
setlocal

SWITCH %1

  CASE fish
    echo It is fish

  CASE fowl
    echo It is fowl

  DEFAULT
    echo It is neither fish nor fowl

ENDSWITCH

If I run the batch file with a parameter of fowl it works as I expect:

Code:
c:\test>test fowl
It is fowl

and if I then comment out the second case with rem, it also works as I expect:

Code:
c:\test>type test.btm
@echo off
setlocal

SWITCH %1

  CASE fish
    echo It is fish

rem  CASE fowl
rem    echo It is fowl

  DEFAULT
    echo It is neither fish nor fowl

ENDSWITCH

c:\test>test fowl
It is neither fish nor fowl

but if I use COMMENT/ENDCOMMENT around the second CASE it doesn't ignore the CASE and gives an error when it encounters the ENDCOMMENT:

Code:
c:\test>type test.btm
@echo off
setlocal

SWITCH %1

  CASE fish
    echo It is fish

COMMENT    
  CASE fowl
    echo It is fowl
ENDCOMMENT
    
  DEFAULT
    echo It is neither fish nor fowl
    
ENDSWITCH

c:\test>test fowl
It is fowl
TCC: C:\test\test.btm [12]  Unknown command "ENDCOMMENT"
 
Tested again with v31 build 11 and COMMENT/ENDCOMMENT is now working as expected within SWITCH statements, thanks Rex.
 

Similar threads

Back
Top