
Recommend to use the same one prefix with all external types, names and functions.
#Vector code c code#
Is the code clear, what can I do to make it easier to follow? I'd expect the same with delete_void_vector(NULL, foo). I'd detect overflow in size computations.įree(NULL) is well defined. Add code to handle doubling array size when size is 0.Ĭreate a VV_DEFAULT_SIZE 16u if desired for the user to call with new_void_vector(VV_DEFAULT_SIZE). Suggest setting aside size = 0 as something special and allow an initial vector size of 0. I see no real value in a default size of 16. It seems odd to have 2 forms of error signaling: error codes and NULL. I'd re-work calls to return an error code on vv_pop(), like vv_err vv_pop(void_vector **vv, void **el). If NULL is not to be allowed (which I think is a bad idea) as a storable void *, vv_push(&vv, NULL) should error. Vv_pop(), vv_read_index() return NULL as an error indicator and can return NULL as a valid return. Void* vv_read_index(void_vector *vv, size_t index) const void* vv_read_index(void_vector *vv, size_t index) The stored ellement is a void *, changing the return type to const is not good.
#Vector code c how to#
I'd expect at least some commentary about the roll of the functions and how to use them near the function declaration section.Īssume a user will read the header and not delve into implementation. I am trying to minimize use of external libraries (although I don't think it would be possible to avoid stdlib.h). =7009= ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) =7009= For counts of detected and suppressed errors, rerun with: -v =7009= All heap blocks were freed - no leaks are possible =7009= total heap usage: 14 allocs, 14 frees, 1,616 bytes allocated =7009= in use at exit: 0 bytes in 0 blocks I ran this through valgrind and got the following output: =7009= HEAP SUMMARY:

Void_vector* new_void_vector(size_t size) I have implemented a simple dynamic vector library in C.
