vector
vector copied to clipboard
safe twins
Basing a design on void * might not be very safe. One added safety measure might be to have a "safe twin" for every function trying to add a new element. For example
/* Insertion */
int vector_push_back_safe(Vector* vector, void* element, const size_t element_size_ )
{
assert(vector != NULL);
assert(element != NULL);
if( vector->element_size != element_size_ ) {
/* apply your error handling policy here */
}
return vector_push_back( vector, element ) ;
}