Paramarray redux

Questions about the BASICtools and MakeItC
Post Reply
olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Paramarray redux

Post by olzeke51 »

Hello Bruce,
In attempting to create an 'AT.bas' file that contains the AT commands
for the esp8266, I was considering using a PARAMARRAY as it was noted
as being 'global'. A) I found that the elements can only be accessed
within the SUB/FUNcTION . I tried to 'DIM PARAMARRAY P' --error, tried
to PRINT P(3) - Undefined Label P
'
B) each time a Paramarray is named (even with the same name; different SUB)
it takes up 64 bytes of RAM for each Paramarray!! - consuming precious RAM
[It will re-use that same memory if the SUB is called a second time]
This conflicts with your statement in the on-line help for 'paramarray':
"There is only one PARAMARRAY allocated for a BASIC program, so a SUB/FUNCTION
using a PARAMARRAY should not call another SUB/FUNCTION with a PARAMARRAY."
'
my program:
DIM Static(15)
dim i
dim paramptr
dim paramptr1
''
SUB Test (paramarray P)
for i = 0 to 14
P(i) = 300 + i
next i
print "sub"
print P(5), P(15)
paramptr = ADDRESSOF P
print paramptr
print
ENDSUB
'
SUB Test1 (paramarray P)
for i = 6 to 14
P(i) = i
Static(i) = P(i)
Static(15) = p(15)
next i
print "sub1"
print P(5), P(15)
paramptr1 = ADDRESSOF P
print
ENDSUB
'
Main:
'
gosub Test(5,4,3,2,1)
gosub Test1(5,4,3,2,1,99,98,97,96,95)
print "main"
print Static(2),Static(7),Static(15)
gosub Test(9,8,7,6)
print paramptr
print paramptr1
END



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: Paramarray redux

Post by basicchip »

Originally the code was going to use a globally defined space for paramarray. That definition is in the firmware and is not directly accessible from BASIC. It is still used by calls to MAIL functions for the Ethernet enabled devices.

But it turned out to be simpler to allocate it like other arrays. So it is unique to each definition, and space for 15 items and 1 count is allocated each time. So I have removed that statement from the help files.

Post Reply