cvector · Section 3
cvec_at_ptr
NAME
cvec_at_ptr - access element at index (type-inferred, returns pointer or NULL)
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cvector.h> element_ptr = cvec_at_ptr(v, index);
DESCRIPTION
Type-inferred wrapper for cvector_at() that gives a pointer to the element, already of the right type, or NULL when the index is out of bounds. Unlike cvec_at, it doesn't stop the program for such an index.
PARAMETERS
v Vector to access index Zero-based index of the element
RETURN VALUE
A pointer to the element at the index, or NULL when the index is out of bounds.
NOTES
An index out of bounds gives NULL and doesn't stop the program. The pointer is valid only until the size of the vector changes.
EXAMPLES
cvec_construct(vec, int); cvec_push(vec, 42); int *ptr = cvec_at_ptr(vec, 0); if (ptr) { *ptr = 5; // Change the element in place } cvec_destroy(vec);