Spurious errors (triggered by "for" construct?) when adding/removing "echo" lines

May 23, 2010
36
1
Seattle
Synopsis: echo statements are inconsistently generating apparently unrelated errors.

Spoiler: problem goes away when I replace the for () construct in the following code chunk with a do/enddo construct. But these results are still mildly interesting.

I have a .btm script that processes one or more filesets, which are specified on the command line. The heart of the script looks like this:
Code:
do while "%1" != ""
    <code here to parse fileset from command line>
    for %recurse_fileset_path %file in (%@quote[%fileset]) (
      <a lotta code here>
::    echo  just before gosub
      gosub COMMIFY filesz
::    echo just after gosub
      <some more code here>
      )
    shift
  enddo
I'm using echo and pause statements (two shown here, commented out) as a poor man's debug. When those statements are turned on (remove the colons), the script does exactly as I expect in TCC 28 (but not in TCC 22). When those statements are either commented out or removed, the script (usually) gives multiple error messages "TCC: C:\batch\ls.btm [169] Unknown command '&'" on what appear to be random iterations of the loop. The number of error messages depends on whether I have removed one or the other or both of the comments, and on which version of TCC I am using. The error message points to that closing right parenthesis. The character "&" does not appear in the script. That character is defined to TCC as my command separator.

Playing with turning the echo statements on and off in two versions of TCC yielded these results.

Code:
                                    Error Msg Count
Situation                v. 22.00.41 x64   v. 28.01.14 x64
  both echo lines active       15                 0
  first (::)ed out              0                 6
  second (::)ed out            11                 0
  both (::)ed out               0                 1
  first (rem)ed out             0                 5
  second (rem)ed out           29                 2
  both (rem)ed out              4                 6
  first removed                41                 0
  second removed                0                 0
  both removed                  0                 0

Adding other echo statements kept changing the error-message counts. Nonetheless, in all other respects, the output of the script was identical and correct in all cases.

So what do the error messages really mean, and what really triggered them?
 
Aug 9, 2009
237
1
( blah
etc..
rem test works as expected in any language
: gets treated as a lable name in tcc/cmd
)
 
Last edited:

rconn

Administrator
Staff member
May 14, 2008
12,404
152
It's impossible to debug this without a reproducible test case (something more than "<a lotta code here>" that demonstrates the problem.

The & is added by the parser to the end of every line inside your FOR command group when everything inside the ( ) is converted to a single line.

As an aside, FOR is not well-suited to the construct here; you'd be much better off using another DO. FOR is constrained by the necessity of CMD compatibility (including emulating some CMD bugs).

As another aside, why use the ECHO statements instead of running the file in the TCC batch debugger?
 

Similar threads