Skip to content

Commit 5f69fb6

Browse files
authored
Document non-default array length types (#114)
1 parent 2290c79 commit 5f69fb6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/tutorials/programming-language/main/02-00-basics/02-04-data-types.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ int[] a = new int[10];
169169
int[] b = { 2, 4, 6, 8 };
170170
```
171171

172+
By default, the type of the array length is `int`, but a different type
173+
can be specified. For example, `uint8[:size_t] data` declares an array
174+
whose indices are `size_t`, which can therefore store any number of
175+
bytes that can be addressed (an `int`-indexed array can only have up to
176+
2^32 elements). Conversely, `string[] list = new string[10:uint8]`
177+
declares an array whose indices are bytes, which might be useful to save
178+
memory when many small array indices are stored.
179+
172180
You can slice an array with `[start:end]`:
173181

174182
```vala

0 commit comments

Comments
 (0)