Probably not what you’re looking for, but if I was approaching this problem I would be tempted to build a linked list of pointers to the elements first and have a function to flatten the list out into a single chunk of data.
Each element in both the list and the array would need a header giving the data type and size in order to manage the data.