I need to create unique instances of a struct and return its address without using malloc.
The problem is everytime I call the function that creates the struct instance, the address to the instance is the same.
inside of List.h
typedef struct List_s List;
struct List_s{
Node* next;
};
inside of List.c
List* List_Create(){
static List head;
printf("%p\n", &head); <--- In both function calls prints out the same address
return NULL;
}
int main(void){
List_Create();
List_Create(); // I
}
I have tried not using the static keyword but the same problem occurs. Additionally, I have put initialized the List struct outside of the function and no problem occurs, but I need to do it inside of a function.
return malloc(sizeof List);realloc(0, sizeof(List))count asmalloc?