vector icon indicating copy to clipboard operation
vector copied to clipboard

safe twins

Open DBJDBJ opened this issue 5 years ago • 0 comments

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 ) ;
}

DBJDBJ avatar Sep 03 '20 07:09 DBJDBJ