1.1 --- a/src/cx/array_list.h Sun Feb 18 13:01:09 2024 +0100 1.2 +++ b/src/cx/array_list.h Sun Feb 18 13:16:38 2024 +0100 1.3 @@ -61,6 +61,18 @@ 1.4 size_t name##_capacity; 1.5 1.6 /** 1.7 + * Initializes an array declared with cx_array_declare(). 1.8 + * 1.9 + * The memory for the array is allocated with stdlib malloc(). 1.10 + * @param array the array 1.11 + * @param capacity the initial capacity 1.12 + */ 1.13 +#define cx_array_initialize(array, capacity) \ 1.14 + array##_capacity = capacity; \ 1.15 + array##_size = 0; \ 1.16 + array = malloc(sizeof(array[0]) * capacity); 1.17 + 1.18 +/** 1.19 * Defines a reallocation mechanism for arrays. 1.20 */ 1.21 struct cx_array_reallocator_s { 1.22 @@ -181,7 +193,7 @@ 1.23 * @param size a pointer to the size of the target array 1.24 * @param capacity a pointer to the target array's capacity - must not be \c NULL 1.25 * @param elem_size the size of one element 1.26 - * @param elem the element to add 1.27 + * @param elem a pointer to the element to add 1.28 * @param reallocator the array reallocator to use, or \c NULL if reallocation shall not happen 1.29 * @return zero on success, non-zero error code on failure 1.30 */ 1.31 @@ -192,10 +204,10 @@ 1.32 * Convenience macro that uses cx_array_add() with a default layout and the default reallocator. 1.33 * 1.34 * @param array the name of the array (NOT a pointer to the array) 1.35 - * @param elem the element to add 1.36 + * @param elem the element to add (NOT a pointer, address is automatically taken) 1.37 */ 1.38 #define cx_array_simple_add(array, elem) \ 1.39 - cx_array_simple_copy(array, array##_size, elem, 1) 1.40 + cx_array_simple_copy(array, array##_size, &(elem), 1) 1.41 1.42 /** 1.43 * Swaps two array elements.