When doing exercise 35, in the testset darray_algos.c
we have a support function called create_words
:
DArray *create_words()
{
DArray *result = DArray_create(0, 5);
The first param (the one with 0) is the element_size
. In my code this runs into an error because I do not accept an element size of zero. This test case would suggest that element size of zero is acceptable.
So I checked the ultimate code in liblcthw on github. It turns out that element_size
is permitted to be zero and if so, the function DArray_clear
will not clear anything. It seems like element_size doubles as an indication whether the library is allowed to free the underlying elements.
This is where I miss specification. Including this testcase, it is difficult to deduce that the element_size
determines whether DArray_clear
really does a free
on elements.
My question is:
- Is this correct? Does
element_size
stand for the element size and for whether the library is allowed to clear? - Should this (in real life) be extensively documented or is it general practice to do it this way?
Kind regards, Guus.