Fixing array examples

This commit is contained in:
Krzosa Karol
2022-07-28 13:20:51 +02:00
parent 4a0234155c
commit 78a0f54319
5 changed files with 44 additions and 24 deletions

View File

@@ -0,0 +1,27 @@
/*
Static arrays are exactly like c arrays, difference is
we can easily then get a slice of that array.
Slices are static arrays + length, they simplify array handling.
This allows us to pass an array into a function easily, then that function
can still access that length information easily.
Passing a pointer to array + length is a common pattern in C. So it would
be nice if handling of that was simplified.
*/
main :: (): int
static_array: [8]int
// We can get size of array using length_of builtin
#assert(length_of(static_array) == 8)
element: int = static_array[0]
assert(static_array[1] == 0)
assert(element == 0)
// Variables are zeroed by default
// assert(static_array[7] == 0)
// for static_array
// it = 1