So here is the problem I'm trying to solve, I'm programming in C.
We have a function that can initialize a struct for you.
typedef struct {
int val1;
int val2;
} custom_t;
custom_t init_custom() {
custom_t temp;
temp.val1 = 5;
temp.val2 = 5;
return temp;
}
And you would just use it like so:
custom_t some_name = init_custom();
I have 4 functions that takes the custom_t as input and can do some work with it.
In another file I have a lot of library functions that will run in a multithreaded enviroment. These library functions will all need to do work on the same custom_t variable, no matter the thread.
The library functions won't get the custom_t variable passed to it, because the goal is that another user should be able to use the library functions without thinking of the custom_t variable.
I'm thinking that I have to make the custom_t variable global in the namespace where I define the library functions but I an error saying that global variables must be const.
I am unsure how to achieve this and I would appreciate all the help I can get. If my explanation wasn't good enough feel free to ask any questions and I will try to elaborate.
EDIT: Fixed the variable init typo