This reference is organized by operation group and focuses on behavior contracts: purpose, preconditions, failure behavior, and complexity.
- Purpose: declare typed
Array(T)andSlice(T)forms. - Preconditions: run before first use of those generated types.
- Failure behavior: none (macro expansion).
- Complexity: compile-time only.
- Purpose: allocate a new
Array(T)with initialcapacity == sizeandcount == 0. - Preconditions: valid type
T;sizeconvertible toarray_size_t. - Failure behavior: returns
NULLon overflow or allocation failure. - Complexity:
O(1)allocation step (allocator-dependent).
- Purpose: release array memory.
- Preconditions: pass the same owning pointer returned by
array_make/growth path. - Failure behavior: none;
free(NULL)is valid. - Complexity:
O(1)call (allocator-dependent release work).
- Purpose: ensure
arr->capacity >= min_capacity. - Preconditions:
arrmust be non-NULL.arrmust be a modifiable lvalue (may be updated afterrealloc).
- Failure behavior: returns
falseon null input, overflow, or allocation failure. - Complexity:
O(1)if existing capacity is enough.O(n)when reallocation moves/copies existing elements.
- Purpose: append one element at the logical end.
- Preconditions:
arrnon-NULL. - Failure behavior: returns
falseifarris null, count overflows, or growth fails. - Complexity: amortized
O(1), worst-caseO(n)on resize.
- Purpose: append without surfacing failure in call sites.
- Preconditions: same as
array_try_push; caller accepts silent failure. - Failure behavior: internally ignores failed push.
- Complexity: same as
array_try_push.
- Purpose: checked element access by index.
- Preconditions:
arrnon-NULLidx < arr->countout_ptrnon-NULL
- Failure behavior: returns
falsewhen any precondition fails. - Complexity:
O(1).
- Purpose: direct index access.
- Preconditions:
arrnon-NULLandidxin range. - Failure behavior: undefined behavior if preconditions are violated.
- Complexity:
O(1).
- Purpose: build checked non-owning slice for half-open range
[low, high). - Preconditions:
arrnon-NULLlow <= high <= arr->countout_slicenon-NULL
- Failure behavior: returns
falseon invalid bounds or null pointers. - Complexity:
O(1)(no element copy).
- Purpose: build non-owning slice without validation.
- Preconditions:
arrnon-NULLand bounds valid. - Failure behavior: undefined behavior if preconditions are violated.
- Complexity:
O(1).
- Purpose: safe pointer to last element.
- Preconditions: none.
- Failure behavior: returns
NULLwhenarrisNULLor empty. - Complexity:
O(1).
- Purpose: pointer to first element slot.
- Preconditions:
arrnon-NULL. - Failure behavior: undefined behavior if
arrisNULL. - Complexity:
O(1).
- Purpose: pointer to last element.
- Preconditions:
arrnon-NULLand non-empty. - Failure behavior: undefined behavior if preconditions are violated.
- Complexity:
O(1).
- Purpose: strict C typed pointer iteration from start to end.
- Preconditions:
arrnon-NULL. - Failure behavior: undefined behavior if
arrisNULL. - Complexity:
O(n)overcount.
- Purpose: inferred-type iteration where
typeofis available. - Preconditions:
ARRAY_HAS_TYPEOFenabled andarrnon-NULL. - Failure behavior: unavailable in strict mode; otherwise same preconditions as typed iteration.
- Complexity:
O(n).
- Purpose: read logical size and emptiness.
- Preconditions:
arrnon-NULL. - Failure behavior: undefined behavior if
arrisNULL. - Complexity:
O(1).
- Purpose: nullable-safe metadata helpers.
- Preconditions: none.
- Failure behavior: none (
NULLmaps to0/true). - Complexity:
O(1).
- Default for new code: checked APIs (
array_try_*,array_reserve, nullable helpers). - Use unchecked compatibility APIs only when preconditions are guaranteed locally and reviewed.
- Zero-capacity arrays grow correctly on first push.
- Size arithmetic is overflow-checked before allocation.
- Failed growth leaves existing array data intact.
- Checked slice creation validates half-open bounds and output pointer.