I want to write in C (there is no particular taste, say, c11) for a general global struct struct array, such as the following pseudocode:
void * generic[] ={&(struct a va),&(struct b vb)};
Now I want to create a function that, given the position identifier of the desired structure (I plan to use a constant for each id, hardcoded), will copy it.
Since this copy() also generic (accepts void * as the destination), it will need to know the strict size that the caller can specify (many errors, it should already provide the target structure and the right id) or I will also support parallel an array of the correct sizeof for each structure.
Is there a way to automate the sizeof array initialization during compilation? Or even implement some kind of trick to instruct the user to simply pass a pointer to a struct without its identifier, without creating a specialized get_struct_x() ?
No dynamic allocation ( alloc() , local variable in order) is allowed, all contents of the structure and the general array are known at compile time.
Sorry for my poor explanation, feel free to improve / fix it.
Edit for clarification: I need to deeply copy the know structure type from the array where many struct types are stored, but the same type is never repeated. And I need to do this from the universal get function, which will be called from another thread, so the mutex is blocked before and after copying, and I want to save all the lock and cast code at one point in order to minimize debugging and create a more efficient test.