DWIM parser?

May 31, 2008
382
2
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 20, 2008
3,515
3
Elkridge, MD, USA
The whole GOSUB is within the scope of the FOR, thus "%icon" is interpreted as in a FOR - %i becomes X (its only value set by FOR), %icon becomes Xcon... Goes back to the days of COMMAND.COM...
 
May 31, 2008
382
2
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
596
14
Norman, OK
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
}
 
May 20, 2008
3,515
3
Elkridge, MD, USA
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.
 
Thread starter Similar threads Forum Replies Date
R Support 5