[Coco] Basic09 local variable storage

CoCo Mongrel cocomongrel at googlemail.com
Tue Jan 26 12:22:00 EST 2010


Hey everybody!

So variables are local to procedures in Basic09, right?  Does that mean that
the storage is allocated dynamically?  If I have a couple procedures that
are called at different times with their own local variables, could Basic09
reuse the same memory for local variables?

procedure main
dim zigfoo:integer

zigfoo:=0
run dothing1(zigfoo)
run dothing2(zigfoo)
end

procedure dothing1
param zigfoo:integer

for x = 1 to 100
 zigfoo:=zigfoo+x
next x
end

procedure dothing2
param zigfoo:integer

for x:= 1 to 100
 print zigfoo
next x
end

The undeclared 'x' variables in each procedure are 'automatic' INTEGERs, is
that right?  Should I worry about the storage for them?  Would it use less
memory to declare an 'x' in the main procedure and pass it to the
subprocedures by reference, or does Basic09 allocate the memory dynamically
for each procedure call?  I'm not asking whether passing 'x' as a parameter
is the right thing to do from the perspective of structured programming,
just trying to understand how Basic09 allocates memory for variables.

CoCoMongrel



More information about the Coco mailing list