Author |
|
Geoffg Guru


Joined: 06 June 2011 Location: Australia
Online Status: Offline Posts: 2272
|
Posted: 22 February 2018 at 5:36pm | IP Logged
|
|
|
Grogster wrote:
But if STATIC is supposed to remain across calls to subs and functions, then STATIC SwState=0 will clear it anyway |
|
|
No, STATIC SwState=0 will just set the initial value for the variable for the first call to the subroutine. On subsequent calls its value will be whatever its last value was. Actually, setting it to zero was redundant as all variables are set to zero when created (including STATIC variables).
I can see that this could cause confusion so I will make sure that the documentation covers it.
Geoff
|
Back to Top |
|
|
MicroBlocks Guru


Joined: 12 May 2012 Location: Thailand
Online Status: Online Posts: 2120
|
Posted: 22 February 2018 at 6:22pm | IP Logged
|
|
|
Static in computer languages means that it is allocated only once and that allocation never changes (remains static) for the entire run of the program, it is also initialized only once. Exactly the same as a global variable although those can be done with DIM. A LOCAL variable will be allocated (storage room for the variable in memory) each time a sub or function is called and it is also initialized each time. LOCAL has scope, meaning that variable is only available within the sub or function. STATIC is a variation of LOCAL. It is still only available within the sub or function but the storage allocation and initial value is done only once.
__________________ Microblocks. Build with logic.
|
Back to Top |
|
|