DynArray is a C header containing X-Macros for the creation and manipulation of dynamically resizing arrays. It includes functions for adding elements, removing elements, and getting and setting array slots.
Most C programmers have to go through a crazy mess of code to get dynamically resizing code arrays.
/* Example of a dynamic array of characters. */
int myarray_count = 0;
char *myarray = NULL;
/* Add an element. */
myarray_count++;
myarray = realloc (myarray, sizeof (char) * myarray_count);
myarray[myarray_count - 1] = 'H';
/* Do this a couple of more times... */
/* Now lets remove a character. */
myarray_count--;
int i;
for (i = 5 /* because we want to remove the element at index 5 */; i < myarray_count - 1; i++)
myarray[i] = myarray[i + 1];
myarray = realloc (myarray, sizeof (char) * myarray_count);
Now that is a lot of work for what should be simple! With DynArray, however, it is easy as a few function calls.
DYNA_DECLARE (char, myarray);
DYNA_INIT (char, myarray);
DYNA_ADD ('H');
/* ... */
DYNA_REMOVE (5);
Beautiful, eh? Download it at https://savannah.nongnu.org/projects/dyna/.
