_STATIC (type field)

From QB64 Phoenix Edition Wiki
Revision as of 12:26, 21 June 2026 by RhoSigma (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The _STATIC field qualifier is used to designate an array member inside a user TYPE definition as non-changeable throughout a program.


Syntax

TYPE MyType
.
. myArray(lb TO ub) _STATIC AS Variable Type
.
END TYPE


Parameters

  • lb and ub are the respective lower bound and upper bound indexes of the array.
  • _STATIC qualifies the array as non-changeable.
  • Variable Type defines the datatype of the array elements. Note that some types may not be allowed for arrays.
    • May also be the name of another user defined TYPE which may also contain array members, hence nested array constructs are possible.


Description

  • This keyword can only be used for array members inside TYPE definitions.
  • There's no connection or interaction with a globally used $STATIC or $DYNAMIC metacommand.
  • The use of _STATIC is optional, array members without an explicit _STATIC or _DYNAMIC field qualifier are static by default.
  • The use of this keyword currently requires the $UNSTABLE:TYPEFIELDS metacommand until all issues around arrays in types have been fixed and stabilized.


Availability


Examples

Example 1
$UNSTABLE:TYPEFIELDS

TYPE TItem
    code(0 TO 2) _STATIC AS INTEGER
END TYPE

REDIM Items(0 TO 2) AS TItem

Items(2).code(0) = 10
Items(2).code(2) = 20

REDIM _RETAIN Items(5) AS TItem '                  Parent size can be changed,
'REDIM _RETAIN items(4).code(0 to 5) AS INTEGER '  but kids size not, because is not _Dynamic!

Items(5).code(0) = 30
Items(5).code(1) = 40

PRINT LBOUND(Items(4).code)
PRINT UBOUND(Items(4).code)

PRINT Items(2).code(0)
PRINT Items(2).code(2)
PRINT Items(5).code(0)
PRINT Items(5).code(1)

Example 2
$UNSTABLE:TYPEFIELDS

TYPE TPoint
    value(1 TO 3) _STATIC AS LONG
END TYPE

DIM points(0 TO 1) AS TPoint

points(0).value(1) = 100
points(1).value(3) = 300

PRINT points(0).value(1)
PRINT points(1).value(3)
Examples by Petr


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link