Welcome!

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

SignUp Now!

Difference between TCC and CMD: variable names with hyphens

Oct
364
17
In TCC 22, 32-bit a difference between TCC and cmd:

Set DEN_a-temp="Hello"

Echo %DEN_a-temp

TCC: -temp
CMD: %DEN_a-temp ( WAD )

Echo %DEN_a-temp%

TCC: -temp
CMD: "Hello"

In the actual usage the variable name stands for "a file with Insurance Denial records in the temporary-hold folder \a-temp". The folder is named "a-temp" so it will display first in File Manager. The data the variable actually holds is a path ending with a slash.
 
Try "OPTION //CmdVariables=Yes".

Code:
v:\> echo %[a-b]
"Hello"

v:\> echo %a-b%
-b

v:\> echo %a-b
-b

v:\> option //cmdvariables=Yes

v:\> echo %[a-b]
"Hello"

v:\> echo %a-b%
"Hello"

v:\> echo %a-b
"Hello"
 
A '-' is technically not a valid variable name character. CMD doesn't care because it requires leading & trailing %'s to delineate the name. TCC only requires the leading character -- unless you want to use an invalid character. Then, either use %[…] or turn on CMDVariables (which will then require ALL variables to have leading & trailing %'s).
 
I found this in the Help, which explains the behavior:

TCC Variables and Functions

"The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $. You can force acceptance of other characters by including the full variable name in square brackets, like this: %[AB##2]. You can also indirectly reference environment variables using square brackets. For example %[%var1] means "the contents of the variable whose name is stored in VAR1".
...
The trailing percent sign that was traditionally required for environment variable names is not usually required by TCC, which accept any character that cannot be part of a variable name as the terminator. However, the trailing percent can be used to maintain compatibility with CMD."

--------------------------
When I saw the code wasn't working I realized TCC was probably treating it as math and was trying to subtract temp from DEN_a, but I was surprised that when I added a closing % TCC didn't consider DEN_a-temp to be a variable name.
 
I'm using "%[…]" syntax personally to increase compatibility with TCC itself (i.e. reduce any doubt about what is considered variable's name).
 
Back
Top
[FOX] Ultimate Translator
Translate