Is it possible to replicate a shared array in pure ANSI-C?
I have this structure that contains an array (for floating at the moment) and some variables such as size and capacity for mutation in the array.
typedef struct _CustomArray
{
float* array;
int size;
int capacity;
} CustomArray;
I use this structure, so I can create an array in pure C, where I can add / remove elements, dynamically expand the size of the array if necessary, etc. everything that the "standard" array does, except that it is made only in C, and now I want to make it so that when you initialize this structure, you can set the data type of the elements that should be held, and at the moment it is capable of store only float data types, but I want to make it so that it can store any data type / other structures. But I do not know if this is possible.
At this point, the function to create this array is:
CustomArray* CustomArray_Create(int initCapacity, )
{
CustomArray* customArray_ptr;
float* internalArray = (float*)malloc(sizeof(float) * initCapacity);
if(internalArray != NULL)
{
CustomArray customArray = { internalArray, 0, initCapacity };
customArray_ptr = &customArray;
return customArray_ptr;
}
return NULL;
}
Is it possible to specify a data type as a parameter so that I can store memory for this data type and dynamically display it as a given data type in an array?
Thanks in advance,
Marnix van Rijswijk