A dynamic array list implementation in C. Works for any type (even your custom structs)
- Include the jplist header file
#include "jplist.h"- Make a print format macro for the types that you will use inside of the JPList struct (used for printing out the list)
#define format_Person(i) "(name: \"%s\", age: %d)", iget(list, Person, i).name, iget(list, Person, i).age- Make a comparison function that gets called when comparing items in the JPList struct (it should act like strcmp from "string.h")
int int_cmp(int x, int y){return x - y;}- Call the "ADD_BASE_FUNC" macro to initialize all of the functions that can be used for the JPList (pass in the type, print format macro you made earlier, and the comparison function)
ADD_BASE_FUNC(int, format_int, int_cmp)IMPORTANT: you cannot use pointers as a type in the list UNLESS you typedef it
For example:
typedef int* int_ptr;
ADD_BASE_FUNC(int_ptr, format_int_ptr, int_ptr_cmp)NOTE: you can also add specific features only by using the "ADD" macros defined in the jplist header file
Since the JPList struct stores the items in a void* so indexing the items directly is a mess,
thats why I added a "IGET" macro
Example usage: \
int val = IGET(ints_list, int, 5);
IGET(ints_list, int, 4) = 21;