IonicWind Software

IWBasic => General Questions => Topic started by: srod on July 27, 2007, 05:17:09 AM

Title: Static variables
Post by: srod on July 27, 2007, 05:17:09 AM
Hi,

does EMBasic support static local variables in subroutines (not merely source global) ?

If not, can I make a feature request...  ;)

Thanks.
Title: Re: Static variables
Post by: Mark1Up on July 27, 2007, 07:36:27 AM
The EBASIC Users Guide is your friend  ;)

Language -> Variables

"EBASIC supports source global, program global and local variables. Source global variables are defined outside of any subroutine and are usable by any part of the code contained within the source file it is defined in. Program global variables are the same as source global but are made usable to any source file in your program by using the GLOBAL keyword. Local variables are defined within a subroutine between the SUB and ENDSUB keywords and are only usable by the code within that subroutine."

Title: Re: Static variables
Post by: srod on July 27, 2007, 08:04:55 AM
Thanks for the reply but, local variables are not necessarily static! By a static variable I mean one that yes is local to the subroutine within which it is defined, but it's value persists between calls of the subroutine. Such values are not stored on the stack alongside other local variables but are either on the heap or within the exe's data section.

Most languages offer static locals. I know that I can use source level variables (in fact that is what I've done), but these are not local of course.  :)
Title: Re: Static variables
Post by: GWS on July 27, 2007, 08:18:34 AM
I don't think you can define a static variable in EBasic ..

It becomes a 'do-it-yourself' job, either using a 'global' to keep track of values between successive calls of the subroutine, or using WRITEMEM, READMEM with memory allocated to store the values.  :)

Graham
Title: Re: Static variables
Post by: srod on July 27, 2007, 08:31:18 AM
Ah, discovering more commands by the day! Thanks.

Title: Re: Static variables
Post by: Ionic Wind Support Team on July 27, 2007, 10:17:12 AM
Aurora supports static variables, Emergence does not.