Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Samples

Open Array

A community discussion post from the original code:zIRON forum.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

Open Array

Version 1.2.1.8 now has better support for arrays and initialized data, so let us take a look at creating an open array in ziron.

program WIN32CUI 'sample';

#include 'ch.zir';

//declare a small block so we can have short strings in our array
block ShortString {
	char text[32];
}

now we can declare our array several different ways

// here we can see the array can hold upto 6 different strings, but we only use 4 of them
ShortString value[6] = ['ziron', ' is my ', 'fav ', 'language!!!'];

or

// here we let ziron count the array items at compile time. 
ShortString value[] = ['ziron', ' is my ', 'fav ', 'language!!!'];
// you may also disregard the [] after value.

and finally we will print our array, so we will end our sample with:

print(@value[0], @value[1], @value[2], @value[3], '\r\n');


wait_key();
ExitProcess(0);

Some other things to note, i have tried to make ziron to be as lenient as possible so it is possible to assign different values in different ways to global variales. I will write a few examples using the same variable name for reference:

Int32 arr[4]; //all array items are null

Int32 arr[4] = 512; //first array entry is 512

Int32 arr[4] = [512, 1024, 2048]; //1-3 array items filled in last is null

Int32 arr[] = [512]; //array length 1, size 4 bytes

Int32 arr = [512, 1024]; //array length 2, size 8

I hope this helps, if you need more help just let me know :)