[Coco] Basic09 local variable storage

Robert Gault robert.gault at worldnet.att.net
Tue Jan 26 16:14:37 EST 2010


CoCo Mongrel wrote:
> 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?

No, "if you do not assign a data type to a variable, BASIC09 assumes the 
variable is real."

>  Should I worry about the storage for them?

No.

>  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?

"When you call a procedure, BASIC09 allocates storage for the 
procedure's variables. ... When you exit a procedure, the system returns 
the storage allotted for the variables, and you lose the stored variables."

> 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