I am trying to implement a generic and dynamic set data structure, yet I am struggling with the generic part. I understand that it is essentially an array of type pointer-to-void
, but I just do not know how to enable the user to choose the type of the elements to add to a particular set. I have searched this site thoroughly, yet there does not seem to be an answer to my question. The dynamic_set
type is defined as follows:
typedef struct
{
int size;
int capacity;
void ** data;
} dynamic_set;
I need to know the type of the elements in order to be able to typecast the pointers and eventually dereference them so that I can check if the sets are compatible for a union, to decide on what type of function to apply to return an aggregate value, etc. Should I include another member in the above structure which represents the type of the elements within that set, like an enum
? Any help is vastly appreciated!