Fixed-size homogeneous data structures.
Overview
Fixed-length arrays are
arrays that have a fixed constant size throughout the execution of a program. The memory used by a fixed-length array to store its elements is allocated at compile-time, either on the stack or in the
.BSS or
.DATA sections of the executable, depending on whether
Static was used to define it. This may allow for quicker program execution since the memory for the array is already allocated, unlike
variable-length arrays, whose element memory isn't allocated until runtime.
Fixed-length arrays with
automatic storage, have their elements allocated on the program stack, and pointers to these elements remain valid only while the array is in scope. The elements of fixed-length arrays with
static storage are allocated in the
.DATA or
.BSS sections of the executable, depending on whether or not they are initialized when defined, so pointers to these elements remain valid for the entire execution of the program. Fixed-length arrays of any storage class cannot be resized during program execution, only
variable-length arrays can.
Declaration and definition
A fixed-length array is declared with the
Extern keyword, followed by a variable identifier, a parenthesized list of one (1) or more subscript ranges and an element
datatype. For an array to be declared fixed-length, either numerical literals,
Const variables or
Enum enumerators can be used as subscript range values.
Const maxLowerBound As Integer = -5
Const maxUpperBound As Integer = 10
'' Declares a two dimensional fixed-length array of elements of type STRING..
Extern arrayOfStrings(maxLowerBound To maxUpperBound, 20) As String
'' Declares a one-dimensional fixed-length array of elements of type BYTE,
'' big enough to hold an INTEGER..
Extern arrayOfBytes(SizeOf(Integer)) As Byte
A fixed-length array is defined with either the
Static or
Dim keywords, following the same form as declaration.
'' Defines a one-dimensional fixed-length array of type SHORT having static storage.
Static arrayOfShorts(420) As Short
'' Defines a one-dimensional fixed-length array of type INTEGER having automatic storage.
Dim arrayOfIntegers(69) As Integer