Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Micromite V5.04.09 Beta 3 Post ReplyPost New Topic
<< Prev Page of 3
Message << Prev Topic | Next Topic >>

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2467
Posted: 22 February 2018 at 5:36pm | IP Logged Quote Geoffg

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.


Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage

Joined: 12 May 2012
Location: Thailand
Online Status: Offline
Posts: 2192
Posted: 22 February 2018 at 6:22pm | IP Logged Quote MicroBlocks

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 View MicroBlocks's Profile Search for other posts by MicroBlocks

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
<< Prev Page of 3
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1406 seconds.
Privacy Policy     Process times : 0.02, 0, 0, 0.12