-
-
Notifications
You must be signed in to change notification settings - Fork 9
Fixed Array Type
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Fixed array types start with a positive integer indicating their length, optionally wrapped in square brackets:
16 int
[16] int
Since it's a type modifier, it can be repeated or combined with other type modifiers:
4 4 float
*10 10 10 bool
$#N 2 double
[$#N] String
[4] [4] [4] double
The size of a fixed array can be defined as a dynamic compile time variable when using square brackets
define ten = 10
define nineteen = 9 + 10
#define twenty_one 21
func exampleFunction {
array1 [ten] int
array2 [nineteen] int
array3 [#get twenty_one] int
}
Elements can be accessed using the []
operator
matrix[0] = 1.0f
In some situations, obtaining the pointer to a fixed array is desired. In order to do this, you can do one of the following:
&my_fixed_array[0]
my_fixed_array at 0
&my_fixed_array as *ElementType
cast *ElementType &my_fixed_array
Rather than hard-coding the length of a fixed array, you can do this:
my_array_length usize = sizeof(my_array) / sizeof ElementType
In order to allow for fixed arrays of any size as function/method arguments, the polycount type modifier can be used:
func reverseFixedArray(array $#N $T) $#N $T {
// ...
}
For more information on polymorphic fixed arrays, see polycount type modifiers