typedef struct _ut_slot {
ucontext_t uc;
....
}*ut_slot;
static ut_slot* table; //array of the structs
void foo (int tab_size){
table = malloc ( tab_size *(sizeof (ut_slot))); // memory allocation for array of structs
for(i = 0 ; i < tab_size ; i++ ){
getcontext(&table[i].uc); <--- ??????
}
}
I receive error in “getcontext” string. How can I write reference to any element of the array? And how can I initialize with “getcontext” command the “uc” field of each array element?
You have an inconsistency with the definition of
ut_slotand the use of it:You say that
ut_slotis a pointer to a struct, then you declareso you have a pointer-to-pointer-to-struct.
You probably want
ut_slotto just be a struct, ortableto be a pointer-to-struct.To be more precise:
tableis a pointer-to-pointer-to-struct, sotable[i]is a pointer-to-struct, and you try to access a struct member of a non-struct withtable[i].ut, which raises a compilation error.Try the following:
the rest of your code is okay and doesn’t need to be changed.