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

SignUp Now!


It appears SETLOCAL/ENDLOCAL does not remove the SETARRAY created within it.

TCC  16.01.45   Windows 7 [Version 6.1.7601]

C:\>echo %@arrayinfo[TestA]


C:\>setarray TestA[5]


C:\>echo %@arrayinfo[TestA]

C:\>setarray TestA[5]
TCC: Array variable is already defined "TestA"

Since SET is used to both modify the environment and to modify array elements, I had expected the array to have been treated as part of the environment saved by SETLOCAL, which also includes aliases and functions. My preference is for the ENDLOCAL to remove any array variables created after the SETLOCAL. However, the documentation for the xARRAY and xLOCAL commands does not say one way or the other. What is supposed to happen? Do we need this check before every SETARRAY?
if %@arrayinfo[ArrayName] NE -1 unsetarray ArrayName
Sorry, Tim, the 4th paragraph of HELP -> SETLOCAL is
SETLOCAL does not save the command history or array variables.
Ever since version 10... You are right that no similar indication is made in topic SETARRAY, but isn't its lack a hint?
BTW, while ALIAS mentions its relationship to SETLOCAL, there is no mention for FUNCTION.

If you feel strongly about extending the scope of SETLOCAL to SETARRAY, I'd support it in principle, but backward compatibility (for users who expect array definitions to survive ENDLOCAL) would be required. One possible method would be to use SETARRAY /L to define LOCAL arrays, i.e., arrays that must be defined within a SETLOCAL / ENDLOCAL pair. Another quirk is implied ENDLOCAL, i.e., a batch program with explicit SETLOCAL that performs ENDLOCAL on exit from the batch, whether or not present. I myself use implied ENDLOCAL whenever possible (laziness, probably not good programming practice).
Thanks, Steve. I don't view not mentioning something as an indication of something else. I like the idea of the SETARRAY /L for local. All of my batch files use the implied ENDLOCAL also. Another variation of SETARRAY I would like is for it to redefine a previously defined array instead of triggering an error.
I agree that being able to redefine an array without making sure it does not exist COULD be nice - but not always. An option (e.g. /F for forced definition) could take care of that. Are you going to submit them to "feedback"?
The /F option should work. I'll let you add it to the /L suggestion. Is there still the other suggestion/vote mechanism? I didn't see it linked from the main site.
Now I see it. When I'm typing this text, I literally cannot see it. I had to force myself to check the margins. I normally try to ignore the margins of pages; that's where the ads are. ;)

Similar threads