WAD SET problem - array element initialization

May 20, 2008
3,515
4
Elkridge, MD, USA
Attempting to initialize a valid array element, with a space-padded array index, fails.
Tested in TCC 11 and 14.02.35.
Note the space character after the [ below.

Assume array is defined using SETARRAY.
Code:
set array[ 0]=0
reports "Invalid array argument (out of bounds)..."
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Illegal syntax != a bug.

The parser cannot blindly assume that all spaces in variables are meaningless. Is there an external overriding reason you can't use the correct syntax?
Where is the illegality of this syntax documented? Unless this restriction in indexing array elements is documented, it is a valid assumption that one can set (or reference the value of) an array element using leading space.

I now noticed another restriction - unlike almost anywhere else, one cannot use a hexadecimal value for the array index, the x of the 0x prefix is considered a field separator, hence the index is considered zero 0 regardless of the actual value.

The main reason (and only one in the test case) to use leading space in the array index of SET commands is vertical alignment of code listing for readability.

IMHO both of these restrictions are bugs unless documented. Once documented we just have to grin and bear it...
 
May 20, 2008
3,515
4
Elkridge, MD, USA
BTW, the [ character is not valid in a variable (or array) name, it terminates the variable name, and indicates the next field in the command is an array index, which must resolve to a numeric value. With a little more effort the parser could accept any expression with a numeric value, leading space or 0x included (though I would not expect it to attempt to perform the functions of an implied @EVAL no matter how nice it would be).
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
Not correct -- the [ character is valid (albeit dumb) in a variable name.

I could check for that in SET if:

(1) nobody cared about CMD compatibility
(2) Nobody cared about existing batch file / alias compatibility, and
(3) If SET had its own private parser -- but it doesn't. I don't think it is of benefit to have every command parse its arguments differently.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
Where is the illegality of this syntax documented? Unless this restriction in indexing array elements is documented, it is a valid assumption that one can set (or reference the value of) an array element using leading space.

That's just silly -- it's not possible to document the infinite number of ways to do something wrong. The documentation shows the correct syntax; you cannot invent an undocumented variation and then insist it is a bug if the parser doesn't correctly interpret your variation. (Why then not allow spaces in command names or unquoted filenames?)

A space is a syntactically meaningful character; it is not reasonable to insist it be ignored some places and interpreted as a separator in others.

I now noticed another restriction - unlike almost anywhere else, one cannot use a hexadecimal value for the array index, the x of the 0x prefix is considered a field separator, hence the index is considered zero 0 regardless of the actual value.

A hex value can be used in a limited number of places (certainly not "almost anywhere"), and it is documented in those places.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
For those of us accustomed to leading zero 0 in a constant to mean octal this is not transparent... But it is not the case in TCC, so I agree, and it even has the advantage that its width is the same even in proportional fonts as that of any other decimal digit, so it improves vertical alignment...
 
May 20, 2008
11,400
99
Syracuse, NY, USA
For those of us accustomed to leading zero 0 in a constant to mean octal this is not transparent... But it is not the case in TCC, so I agree, and it even has the advantage that its width is the same even in proportional fonts as that of any other decimal digit, so it improves vertical alignment...
I have only seen such octal notation with a leading'\', as in '\015\012' for a newline. Is there anywhere where the '0' is actually leading?
 
Similar threads
Thread starter Title Forum Replies Date
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
cxxl Set encoding for batch file Support 4
vefatica SET /A var\=...? Support 10
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3
rps Fixed Win "set /p" not working in V17 build 53 Support 3
vefatica SET /A "var%=N", TCC vs. CMD Support 0
J Set environment variable from stdout of command Support 3
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
R WAD /= size ranges not set correctly Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
Roedy SET= Support 2
A How to? Set up a log file for all command output Support 3
M Fixed character set in dir/copy Support 3
Phileosophos Fixed TakeCommand exits upon "set [" command Support 14
R How to set comspec to point to cmd.exe? Support 5
C Wildcard expansion in FOR set Support 27
vefatica SET question Support 16
T Set 1% then Echo 1% Support 9
S SET /A question; HELP nits Support 8
noahcoad copy /w to FTP does not set time stamp Support 1
M A request for a new feature for the "set" command... Support 5
cgunhouse Accessing variables set using SET /U or SET /S Support 3
D Force For to treat set of values as text, not files Support 3
vefatica Regular expressions in FOR's set? Support 10

Similar threads