Given this struct
struct node {
struct node* next;
union {
int lockId;
pthread_t threadId;
} id;
};
What is the correct way to initialize a dynamic array using malloc/realloc to store pointers to this struct?
I have tried:
struct node* nodes = (struct node*)malloc(n * sizeof(struct node*));
but I when compiling I get an error saying: initializer element is not constant
even though I am using #define MAXNODES 10
As for now, I am currently using a static array (fixed-size) by doing:
node *(nodes[MAXNODES]);
Any help would be greatly appreciated!