I am currently writing C LIBRABY where I need to use static void *.
In my first version, I put all my functions that need access to my void * in the same C file in which it was declared, for example:
main.c
int main()
{
function_using_list();
}
foo.c:
void *list=NULL;
void *function_using_list()
{
}
In my second version, I made a small get / set function, so I can access my list through it from anywhere in my code:
foo.c
void *getset_list(void nlist, int action)
{
static void *list = NULL;
if (action == 1)
return (list)
else
list = nlist;
}
What are the pros and cons of these two different projects? Is the second safe?
PS: I just realized that I forgot something in my question: this code is intended to be used as a library.
source
share