Hi Aaron, memory allocation works a little bit differently to either of the options you suggest. It took me a while to understand that the alloc functions are
overloaded on return type (unlike C). All of the alloc functions (zalloc, salloc, halloc) return a pointer of some type, and have as an optional argument an integer specifying how many things of that type to allocate (default is 1). So because you have told the compiler
test is of type i8**, which the compiler thinks of as (i8*)*, it will allocate one i8* worth of memory, which at the moment means 64-bits (until a 32-bit version of extempore is released). If you want an array of cstrings (which I think is what you are trying to do), one way to achieve that would be as shown below.
String literals in xtlang are null terminated yes. In this context null means 0:i8
;; Allocate all the memory for an array of cstrings
(bind-func create_array_of_cstrings:[i8**,i64,i64]*
(lambda (num_strings:i64 max_string_length:i64)
(let ((output:i8** (zalloc num_strings)))
(doloop (i num_strings)
(let ((str:i8* (zalloc (+ max_string_length 1))))
(pset! output i str)))
output)))
;; Put some values in
(bind-val my_cstring_array i8** (create_array_of_cstrings 4 255))
($ (pset! my_cstring_array 0 "Hello"))
($ (pset! my_cstring_array 1 "World"))
;; Check out the bit pattern that terminates the first string - output should be 00000000
($ (print_byte (i8toi64 (pref (pref my_cstring_array 0) 4))))