Welcome!

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

SignUp Now!

DWIM parser?

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]
 
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...
 
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.
 
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
}
 
No doubt, but in C++ there's no difference between one-letter and multicharacter variable names.
 
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.
 
Back
Top