Repository navigation
procedures Static
Home › Variable Declarations › Static
Defines variables, objects and arrays having static storage
Static symbol1 [ (array-dimensions) ] As DataType [ = expression] [, symbol2 [ (array-dimensions) ] As DataType [ = expression], ...]
Static As DataType symbol1 [ (array-dimensions) ] [ = expression] [, symbol2 [ (array-dimensions) ] [ = expression], ...]
Static Var symbol1 = expression [, symbol2 = expression, ...]
Sub|Function procedurename ( parameters ) [[ ByRef ] As DataType] Static
...
End Sub|Functionsymbolarray-dimensionslower-bound To upper-bound [, ...] or Any [, Any...] or empty. expression
Specifies static storage for variables, objects and arrays; they are allocated at program startup and deallocated upon exit. Objects are constructed once when they are defined, and destructed upon program exit.
When declaring static arrays, only numeric literals, Constants or Enumerations may be used as subscript range values. Static variable-length arrays must be declared empty (no subscript range list) and resized using ReDim before used.
In both iterative and recursive blocks, like looping control flow statements or procedures, static variables, objects and arrays local to the block are guaranteed to occupy the same storage across all instantiations of the block. For example, procedures that call themselves - either directly or indirectly - share the same instances of their local static variables.
A static variable may only be initialised with a constant value: its starting value is set at the start of the program before any code is run, and so it cannot depend on any variables or functions in it.
When used at procedure definition level (forbidden at declaration line level), Static specifies static storage for all local variables, objects and arrays, except temporary types and internal variables (objects not explicitly declared).
At module-level variable declaration only, the modifier Shared may be used with the keyword Static to make module-level static variables visible inside procedures.
When used with in a user-defined type, Static creates Static Member Procedures Or Variables.
- Variables cannot be initialised in the -lang qb dialect.
- QuickBASIC allows variables and arrays to be declared using the
Statickeyword within procedures andDEF FNroutines only.Staticforces local visibility of variables and arrays in QuickBASICDEF FNroutines. FreeBASIC supports neitherDEF FNroutines nor this usage ofStatic.
Static (Member)-
Dim,ReDim SharedByref (Variables)-
Sub (Module),Function (Module) -
Sub (Member),Function (Member) Option Static
Sub f
'' times called is initially 0
Static timesCalled As Integer = 0
timesCalled += 1
Print "Number of times called: " & timesCalled
End Sub
'' the static variable in f() retains its value between
'' multiple procedure calls.
f()
f()Will output:
Number of times called: 1
Number of times called: 2Category: Variable Declarations
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing