Welcome!

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

SignUp Now!

Timer issue

samintz

Scott Mintz
May
1,582
27
I was testing Vince's timing issue with arrays and noticed an odd issue with the TIMER command.
Code:
setarray /f a[100]
timer do i=0 to 99 (set a[%i]=0)
TCC: Invalid array argument (out of bounds) "a[100]"
...
TCC: Invalid array argument (out of bounds) "a[100]"
Timer 1 off: 14:51:15  Elapsed: 0:00:00.055

I had to double the %'s - set a[%%i]=0 - in order to get rid of the TCC error.

If I change the command to be timer & do ... & timer off then it works as I expected it to.

Why do I need to double the %'s ?

-Scott
 
TCC 26.00.26 x64 Windows 10 [Version 10.0.18362.720]
TCC Build 26 Windows 10 Build 18362
 
I don't know the details, but that version of TIMER doesn't get parsed like many other things. Here's another.

Code:
v:\> (echo foo & echo bar)
foo
bar

v:\> timer (echo foo & echo bar)
Timer 1 on: 15:07:26
More?

Fix that one thus:

Code:
v:\> timer (echo foo ^& echo bar)
Timer 1 on: 15:08:15
foo
bar
Timer 1 off: 15:08:15  Elapsed: 0:00:00.002
 
I was testing Vince's timing issue with arrays and noticed an odd issue with the TIMER command.
Code:
setarray /f a[100]
timer do i=0 to 99 (set a[%i]=0)
TCC: Invalid array argument (out of bounds) "a[100]"
...
TCC: Invalid array argument (out of bounds) "a[100]"
Timer 1 off: 14:51:15  Elapsed: 0:00:00.055

I had to double the %'s - set a[%%i]=0 - in order to get rid of the TCC error.

If I change the command to be timer & do ... & timer off then it works as I expected it to.

Why do I need to double the %'s ?

-Scott

Because the command line is being parsed twice - once for TIMER, and then again for the DO.

The TIMER argument is intended for simple commands; it's not well suited for handling loops or command groups.
 
I don't know the details, but that version of TIMER doesn't get parsed like many other things. Here's another.

Code:
v:\> (echo foo & echo bar)
foo
bar

v:\> timer (echo foo & echo bar)
Timer 1 on: 15:07:26
More?

Fix that one thus:

Code:
v:\> timer (echo foo ^& echo bar)
Timer 1 on: 15:08:15
foo
bar
Timer 1 off: 15:08:15  Elapsed: 0:00:00.002

That would require a custom parser for TIMER on the (remote) chance that you're passing it a command group. Otherwise, when the parser is evaluating the TIMER line, it will break the line at the first &.

I don't think you'd be happy if the parser suddenly decided to evaluate possible command groups inside everything:

echo This is a line (and this isn't a command group)
 

Similar threads

Back
Top