May 03, 2024, 11:05:44 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Static variables

Started by srod, July 27, 2007, 05:17:09 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

srod

Hi,

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

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

Thanks.

Mark1Up

July 27, 2007, 07:36:27 AM #1 Last Edit: July 27, 2007, 07:42:10 AM by Mark1Up
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."


srod

July 27, 2007, 08:04:55 AM #2 Last Edit: July 27, 2007, 08:15:42 AM by srod
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.  :)

GWS

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
Tomorrow may be too late ..

srod

Ah, discovering more commands by the day! Thanks.


Ionic Wind Support Team

Aurora supports static variables, Emergence does not.

Ionic Wind Support Team