cvector · Section 3
cvec_construct
NAME
cvec_construct - type-inferred vector construction
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cvector.h> cvec_construct(vec_name, type);
DESCRIPTION
Type-inferred macro that creates a vector and works out the element size from the type. It also makes a type marker variable, which tells the other type-dispatching macros the declared element type wherever you call them.
PARAMETERS
vec_name Name of the vector variable to create
type Element type, for example int, double or struct foo
Any type name works, a function pointer type such
as void (*)(int) and an array type such as int[4]
included. For an array element type, give
cvec_push(3) an array or a string literal, whose
bytes the macro copies into the element
NOTES
The macro stops the program when an allocation fails. The hidden type marker variable that it makes is read by the other type-dispatching macros, and cvec_redeclare(3) makes it again in another scope. It is equivalent to cvector_create(sizeof(type), &err) plus the error handling.
EXAMPLES
cvec_construct(my_vec, int); cvec_push(my_vec, 42); cvec_destroy(my_vec);