Page 1 of 2
Colon Philosophy
Posted: 13 Oct 2011 13:08
by shadeclan
No, I'm not talking about the one connected to your anus, moron!
In goto statements, it seems that colons are almost always optional. For example:
... seems just as valid as ...
Only in cases of the implicit label
EOF is it required:
My question is this - is there some advantage or disadvantage in colon usage? Has anyone found cases where a colon was or was not required in a goto statement?
See Ed? I still come here!
Re: Colon Philosophy
Posted: 13 Oct 2011 14:07
by nitt
shadeclan wrote:No, I'm not talking about the one connected to your anus, moron!
That wasn't that funny...
And you never need the colon with tags.
AssemblyCode: Select all
org 100h
tag:
mov ah, 09h
mov dx, msg
int 21
jmp tag
C++Code: Select all
#include <iostream>
int main() {
tag:
std::cout << "hi";
goto tag;
}
Batch
Re: Colon Philosophy
Posted: 13 Oct 2011 22:34
by Rileyh
Nitt,
There is no point in explaining the question in assembly.
org 100h
tag:
mov ah, 09h
mov dx, msg
int 21
jmp tag
And in most cases, the colon is not needed to goto a tag.
But it does not affect the capability of the code. I just use the colon out of habit.
Re: Colon Philosophy
Posted: 14 Oct 2011 00:18
by !k
(is the same as) goto :a
until you do not use an editor with code coloring
Re: Colon Philosophy
Posted: 14 Oct 2011 08:35
by shadeclan
nitt wrote:shadeclan wrote:No, I'm not talking about the one connected to your anus, moron!
That wasn't that funny...
Forgive the potty humor - I was trying to cut folks off "at the pass" as we say here in the US.
!k wrote:until you do not use an editor with code coloring
I, myself, use
PSPad for batch editing. It does a pretty good job of highlighting except in
two instances: indented labels, such as:
Code: Select all
:NormalLbl (normal highlighting)
...Code...
:IndentedLbl (no highlighting)
...More code...
and internal function calls, such as:
Code: Select all
call:SomeFun (Label name is not highlighted)
It handles goto statements both with and without colons. By the way Ed, it actually supports a Dutch version!
Re: Colon Philosophy
Posted: 14 Oct 2011 11:32
by Ed Dyreen
shadeclan wrote:...
My question is this - is there some advantage or disadvantage in colon usage? Has anyone found cases where a colon was or was not required in a goto statement?
See Ed? I still come here!
The colon is no longer required since XP. It's still used in batches that need to be compatible !
Or was it the other way around ? Damnet
now I am confused myself, there is a difference, otherwise I wouldn't have written code like:
Code: Select all
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@rem:: Suppress all 'direct call' related errors, all Windows OSes.
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@rem::(
@ if "%$ScriptHost.FullPathFile%"=="" 2>nul goto :ENDOLDOS ()
@ if "%$ScriptHost.FullPathFile%"=="" 2>nul goto ENDOLDOS ()
@rem::)
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Code: Select all
:ENDOLDOS ()
@rem ::
@rem :: Exit 'old' OS
@rem ::
@rem ::(
@rem :: Initialize 'old' OS
@rem ::(
@ echo Off
@rem ::)
@rem :: Print reason
@rem ::(
@ echo.
@ echo. Direct call to SubRoutine not allowed ^!
@rem ::)
@rem :: Pause until user confirms
@rem ::(
@ 2>nul set "?= " <nul
@rem ::
@ pause
@rem ::)
@rem :: CLearScreen may be needed to force close on exiting an 'old' OS
@rem ::(
@ cls
@rem ::)
@rem :: OS may not support the 'exit error' command
@rem ::(
@ 2>nul exit 1
@rem ::)
@rem :: OS should support the 'goto EOF' command
@rem ::(
@ goto EOF
@rem ::)
@rem ::
goto EOF ()
@rem ::)
Re: Colon Philosophy
Posted: 14 Oct 2011 11:38
by shadeclan
I was wondering when you'd show up!
Ed Dyreen wrote:now I am confused myself, there was a difference ...
Well, think about it and let me know.
Re: Colon Philosophy
Posted: 14 Oct 2011 17:02
by nitt
Rileyh wrote:Nitt,
There is no point in explaining the question in assembly.
-_- Is Assembly
really the only one you noticed? Did you miss the C++ and Batch example?
My point was exactly what I said before it, that you never need to use the colon when "going to" a tag.
Re: Colon Philosophy
Posted: 17 Oct 2011 06:29
by shadeclan
nitt wrote:-_- Is Assembly really the only one you noticed? Did you miss the C++ and Batch example?
Actually,
I noticed, although I am ignorant of any C language
and don't know assembly
.
Assembly has always fascinated me but I have never had the time to learn.
Re: Colon Philosophy
Posted: 17 Oct 2011 13:18
by nitt
shadeclan wrote:nitt wrote:-_- Is Assembly really the only one you noticed? Did you miss the C++ and Batch example?
Actually,
I noticed, although I am ignorant of any C language
and don't know assembly
.
Assembly has always fascinated me but I have never had the time to learn.
I don't know Assembly, either. But I know a lot of it.
http://www.youtube.com/watch?v=mWeh3_ITG7M27 tutorials, and hopefully a 28th eventually, they break down all of what I know into the simplest of terms.
Re: Colon Philosophy
Posted: 17 Oct 2011 13:25
by shadeclan
Nice. Thanks - I'm saving the link. Assembly appears to be a dying skill but I have great respect for those who take the time to learn and use it.
Re: Colon Philosophy
Posted: 25 Oct 2011 16:03
by dbenham
(original post deleted) Never mind - I was not distinguishing between GOTO LABEL vs. CALL LABEL.
Since GOTO LABEL without the colon works, I just assumed CALL LABEL works as well. Well it doesn't.
Dave Benham
Re: Colon Philosophy
Posted: 26 Oct 2011 06:40
by shadeclan
dbenham wrote:(original post deleted) Never mind - I was not distinguishing between GOTO LABEL vs. CALL LABEL.
Since GOTO LABEL without the colon works, I just assumed CALL LABEL works as well. Well it doesn't.
Dave Benham
Yup.
Just for giggles, I tried calling a label in a batch job from a different batch job, ie: [call otherbatch.bat:otherlbl] - fortunately, it didn't work. I've learned a lot about batch scripting since I started frequenting this site - I've built beautiful libraries of routines I use every day. I would have been a little upset if I'd built the interface to those libraries for nothing or if there was a way to circumvent the interface - I do some error checking there.
Re: Colon Philosophy
Posted: 28 Oct 2011 12:11
by shadeclan
Here's a thought. Since in the command "goto:eof" the colon is required, wouldn't it be a good idea to always use the colon for other labels so that, if you are a sieve-mind like myself, you don't forget it when coding "goto:eof"?
Re: Colon Philosophy
Posted: 28 Oct 2011 13:46
by aGerman
:eof is no label. It's only a virtual expression which tells the parser to jump to the end of file. For that reason only for goto :eof needs the colon.
Regards
aGerman