DWIM parser?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
May 31, 2008
376
2
#1
Running the batch file at the bottom, I expected to see output
Code:
(ABC)
() ()
Instead I got
Code:
(ABC)
(Xcon) ()
WAD, DWIM or something else? I wasn't able to ascertain if the help file does say that %[name] and %name% are equivalent forms, I thought they are under all circumstances.
Code:
@echo off
setlocal
for %i in (X) (gosub LBL "%i")
endlocal
quit
:LBL
set icon=ABC
echo (%icon%)
unset icon
echo (%icon%) (%[icon])
return
TCC LE 13.03.38 Windows 7 [Version 6.1.7601]
 
May 31, 2008
376
2
#3
So that's one more reason for getting in the habit of using %[name] instead of %name or %name%. %[name] seems to give consistent results under all circumstances.
 
Jan 19, 2011
559
7
Norman, OK
#5
Or it's one more reason not to use single-character FOR variables.
That's a hard to habit to break. I bet if I had the TCC source code in front of me, in it I'd probably find something similar to the following...

Code:
for (int i=0;i<10;i++) {
  // some code here
}
 
#7
No doubt, but in C++ there's no difference between one-letter and multicharacter variable names.
Nor in any other compiled language, AFAIK. Even among interpreted languages this one stands alone - I know of no other case but COMMAND.COM and its supersets, and even those only when declared in a FOR command, that single out single-character variable names for unique treatment. For TCC this behavior is thoroughly documented in the description of the FOR command, in the "Other Notes" section.