SPC  Version 0.9.5
 All Files Functions Groups Pages

SPC also support arrays.

Arrays are declared the same way as ordinary variables, but with an open and close bracket following the variable name. Arrays must either have a non-empty size declaration or an initializer following the declaration.

int my_array[3]; // declare an array with 3 elements

To declare arrays with more than one dimension simply add more pairs of square brackets. The maximum number of dimensions supported in SPC is 4.

bool my_array[3][3]; // declare a 2-dimensional array

Arrays of up to two dimensions may be initialized at the point of declaration using the following syntax:

int X[] = {1, 2, 3, 4}, Y[]={10, 10}; // 2 arrays
int matrix[][] = {{1, 2, 3}, {4, 5, 6}};

The elements of an array are identified by their position within the array (called an index). The first element has an index of 0, the second has index 1, and so on. For example:

my_array[0] = 123; // set first element to 123
my_array[1] = my_array[2]; // copy third into second

SPC also supports specifying an initial size for both global and local arrays. The compiler automatically generates the required code to correctly initialize the array to zeros. If an array declaration includes both a size and a set of initial values the size is ignored in favor of the specified values.

task main()
int myArray[10][10];
int myVector[10];