Show/Hide Toolbars

XSharp

Purpose

Declare and initialize static variables and arrays.

Syntax

STATIC [LOCAL] <idVar> [:= <uValue>] [, ...] [AS | IS <idType>] [, ...]
STATIC [LOCAL] DIM <ArraySpec> [, ...] AS | IS <idType> [, ...]
STATIC [LOCAL] <ArraySpec> [, ...] [AS ARRAY] [, ...]

 

Note: The STATIC statement is shown using several syntax diagrams for convenience only.  You can declare variables, dynamic arrays, and dimensioned arrays using a single STATIC statement if each definition is separated by a comma.

 

 

<idVar>A valid identifier name for the local variable to declare.

 

<uValue>The initial value to assign to the variable.
 
For LOCAL, this can be any valid expression.
 
For STATIC LOCAL, this value can be a literal representation of one of the data types listed below or a simple expression involving only operators, literals, and DEFINE constants; however, more complicated expressions (including class instantiation) are not allowed.
 
Note:  Although <uValue> can be a literal array, it must be one-dimensional.  Multi-dimensional literal arrays are not allowed.  For example, {1, 2, 3} is allowed, but {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} is not.
 
Note:  Although the Chr() function cannot be used in <uValue>, the _Chr() operator can.   _Chr() is otherwise identical in functionality to Chr().
 
If <uValue> is not specified, the initial value of the variable depends on the data type you declare (e.g., NIL if you do not use strong typing, 0 for AS INT, etc.)

 

DIM <ArraySpec>The specification for a dimensioned array to declare.

 

<ArraySpec>The specification for a dynamic array to declare.
In both cases, <ArraySpec> is one of the following:
<idArray>[<nElements>, <nElements>, <nElements>]
<idArray>[<nElements>][<nElements>][<nElements>]
All dimensions except the first are optional.
 
<idArray> is a valid identifier name for the array to declare.  For dynamic arrays, array elements are initialized to NIL.  For dimensioned arrays, the initial value of the elements depends on the data type as explained above for <uValue>.
 
<nElements> defines the number of elements in a particular dimension of an array.  The number of dimensions is determined by how many <nElements> arguments you specify.
 
<nElements> can be a literal numeric representation or a simple numeric expression involving only operators, literals, and DEFINE constants; however, more complicated expressions (such as function calls) are not allowed.

 

AS <idType>Specifies the data type.  If omitted, then depending on the compiler options the type will be either USUAL or determined by the compiler.

 

 

 

IS <idType>Specifies a structure data type in which the memory needed to hold the structure is allocated on the stack (<idStructure> is the only <idType> allowed with the IS keyword.) See the VOSTRUCT entry in this guide for more information on data structure memory allocation.

 

AS ARRAYFor dynamic array declarations, specifies the data type of the entire array.

 

<arrayName>Variable name of array . The array will have the dimensions as declared with <nRows> and <nColumns>. The array may be declared with parentheses as delimiters but also with square brackets.
We recommend the use of square brackets.

Description

The STATIC keyword serves as a lifetime modifier for variables declared with the LOCAL statement, preventing them from being released from memory when the creating entity returns to its calling routine.  It is listed here as a separate entry because, the LOCAL keyword being optional, STATIC can stand alone in a routine as a variable declaration statement.  Refer to the LOCAL statement for a description and notes concerning static variable declarations.

See Also