Maybe :: should not be used for comments so often (or better never)

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Maybe :: should not be used for comments so often (or better never)

Post by MigrationUser »

03 Nov 2012 00:35
npocmaka

After the my little game here ->

Code: Select all

@echo off
::^
echo this will not be printed

::^

echo neither this
 
rem do not set empty line or other symbols at the end
::>(^
Moreover you need two consecutive lines starting with : lines if you want to use this as a comment within parentheses. Not to mention you can unintentionaly close the parentheses context(or open a new one EDIT: you can't):

Code: Select all

@echo off
if 1 EQU 1 (
	echo this will be printed
	::this bellow is not exactly a comment /and this line will constantly print an error for not found device/
	::)
) esle (
	echo unfortunately this also
)
But parentheses are completely different level of pain in the ass (may be they deserve a new thread )

By the way

Code: Select all

:&
:>
:<
:|
I couldn't find a way to access line starts with these neither with goto nor with call (is it possible?).Anyway ^ at the end still can spoil everything .

Last edited by npocmaka (03 Nov 2012 12:48)

----------------------------

#2 04 Nov 2012 08:46
jeb
npocmaka wrote:

By the way

Code: Select all

    :&
    :>
    :<
    :|
I couldn't find a way to access line starts with these neither with goto nor with call (is it possible?).Anyway ^ at the end still can spoil everything .
The simple cause, it's not possible as you created empty labels.
Like in ::, also &<>| are stop characters in a labelname, they do not belong to the name.

You can test it with.

Code: Select all

goto :myLabel

:myLabel&xyz
echo Label found
exit /b
jeb

----------------------------

#3 04 Nov 2012 14:37
Simon Sheppard

Whats happening here will affect any label. I think the command processor is expecting (not unreasonably) that a label will be followed by at least one command before the code block is ended with a closing bracket. That way if you jump to the label it will have something to execute.

Code: Select all

@echo off
if 1 EQU 1 (
	Echo this will be printed
	::this is a comment
        :mylabel
	Echo All done
) else (
	Echo this wont print
)
I've added a note about this here: https://ss64.com/nt/rem.html

Last edited by Simon Sheppard (04 Nov 2012 14:52)

----------------------------

#4 04 Nov 2012 18:38
npocmaka


Thanks Simon.
At least the error message can be avoided ( it's a potential place where break can be used :D ).

But my main ache keeps to be the broken brackets context..
Inside brackets this will work:

Code: Select all

rem comment )
but this will not

Code: Select all

::comment )
(escaping the bracket works.And inside a label brackets context cannot be open.)

(As i find this while I've tried to comment a nested IF - it could be confusing)

@Jeb:
So the they can be used as a comments with same success as semi columns ?Except that they will be not typed so fast.

Last edited by npocmaka (04 Nov 2012 19:06)

----------------------------

#5 04 Nov 2012 19:18
Simon Sheppard


And heres a strange thing

These will fail

Code: Select all

(
:label1
)
) was unexpected at this time

Code: Select all

(
:label1

)
The syntax of the command was incorrect

But this will work

Code: Select all

(
:: any comment
:label1
)
----------------------------

#6 04 Nov 2012 19:32
npocmaka


here's jeb's explanation
https://ss64.org/viewtopic.php?f=2&t=118
----------------------------

#7 04 Nov 2012 23:01
carlos


:: (double dot)(double dot)
Technically it is not a comment, it is a empty label, that can be followed by text that is ignored, because a label occupies all the line.

In windows Nt the labels inside a batch file have a max length of 10 characters. It begin with the double dot (:) character and ends with a space character or the double dot(:) character.

A label call referenced by the name, optionally ending the name with a double dot (:) character.

If you use a label or empty label inside brackets you need followed it with a internal or external command.

Works:

Code: Select all

(
::empty_label_1
echo.inside
)

(
::empty_label_1
rem
::empty_label_2
echo.inside
)
Don't works:

Code: Select all

(
::empty_label_1
::empty_label_2
echo.inside
)
Last edited by carlos (04 Nov 2012 23:01)

----------------------------

#8 04 Nov 2012 23:48
Simon Sheppard
carlos wrote:

In windows Nt the labels inside a batch file have a max length of 10 characters. It begin with the double dot (:) character and ends with a space character or the double dot(:) character.
I'm sure that under XP you can have labels over 100 characters long

goto :abcdefghijklmnopqrstuvwxyz
:abcdefghijklmnopqrstuvwxyz
echo abcdefghijklmnopqrstuvwxyz

Interesting about the : terminator, but also CR/LF will terminate the label.

----------------------------

#9 05 Nov 2012 01:44
carlos
Simon Sheppard wrote:

I'm sure that under XP you can have labels over 100 characters long

goto :abcdefghijklmnopqrstuvwxyz
:abcdefghijklmnopqrstuvwxyz
echo abcdefghijklmnopqrstuvwxyz

Interesting about the : terminator, but also CR/LF will terminate the label.
I remember that in windows xp you can have a labels with more than 10 characters, but when you call it with goto or call it only read the first ten characters (in windows nt are 8), because it, in windows xp the labels:
:label67890
:label67890a
:label67890b

are the same, but apparently it was changed in windows 7.

Last edited by carlos (05 Nov 2012 01:46)

----------------------------

#10 05 Nov 2012 19:05
Simon Sheppard


I tested this on Windows 2008 and XP sp3, it looks like the limit for a label is 127 characters

Code: Select all

@echo off

goto abcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuv

echo start

:abcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuv1

echo middle

:abcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuv

echo end


Online
Post Reply