Common libraries and data structures for C
Okay, I love C so of course I had to take a look. The buzzwords are impressive, with all the testing and CI and so on, really nice, modern and ambitious.<p>I dove into the code, literally looking at the first true part of the implementation in array&#x2F;sc_array.h.<p>Two observations, from probably less than tree minutes of reading:<p>1. The nomenclature with &quot;sc_array_term()&quot; as the destructor (the opposite of sc_array_init()) was new to me; I&#x27;m not saying that&#x27;s a real problem but it&#x27;s at least adding friction in a way. I would have expected sc_array_free(), but that seems to be internally used as an alias for the standard function free(). Very confusing, since that name (sc_array_free()) then leaks into the source but it has the feeling of being meant for internal use.<p>2. I wonder if this has a bug:<p><pre><code>    &#x2F;**
     * Deletes items from the array without deallocating underlying memory
     * @param a array
     *&#x2F;
    #define sc_array_clear(a) \
    do {                                                                   \
      (a)-&gt;cap = 0;                                                  \
      (a)-&gt;size = 0;                                                 \
      (a)-&gt;oom = false;                                              \
    } while (0)
</code></pre>
In my experience, when you want to clear a dynamic array but keep the allocated memory, the &#x27;capacity&#x27; (&#x27;cap&#x27;, here) field should <i>not</i> be cleared. I think this will leak memory if an array is grown, cleared, and then re-filled since the sc_array_add() function will see a zero capacity, and allocate new storage.<p>Just my inflation-devalued SEK 0.02, and I did <i>not</i> run the code, I just read it very quickly. Corrections welcome.