I am trying to implement a bigInt library. I have been checking other libraries like GMP, ttmaht or libtommath but any of them fulfill the requirements of the project (because licenses, because they only use the stack, etc)
I will follow the approach of libtommath (really well documented and written all in C) but I want all stored in the heap. libtommath implements bigInt in an structure like this one:
typedef struct {
int used, alloc, sign;
mp_digit *dp;
} mp_int;
As you can see it has an indirection for accessing the values. (mp_digit are the digits of the big integer). I want to get off the indirection so have some kind of similar struct in the heap where the last element is a mp_digit[] where the size can be different for each instance of mp_int.
I could do it using void* and malloc() knowing that the first X positions are int's with information (used, alloc, sign, etc) and then access to the mp_digit[] knowing the offset but I do not like this idea. I wonder which would be a better approach.
I found other similar questions like this one or this one but they do not store all in the heap so mine is a bit tricky/different.
Thank you,