Update static variable outside of the file without modifying the file in which the static variable is declared in C lang.
Proj1 creates dll. Proj1 has abc.h
file and it is defined as below :
static BOOl stvar = False;//declared as global static variable
func1()
{
stvar= TRUE;
}
func2()
{
if(stvar == TRUE)
{
....
}
else
{
func1(); //call to func1 sets STVAR = TRUE;
}
}
Proj2 Creates exe. It has cprog1.c
file. cprog1.c
file is defined as follows:
cprogfunc1()
{
func2(); //call to func2 sets STVAR = TRUE;
}
cprogfunc2()
{
stvar = FALSE;
func2();
}
We are setting stvar
to false in cprogfunc2()
to make it execute else block in func2()
of abc.h file
. But the value we set in cprogfunc2()
under cprog1.c
is not reflected in abc.h
file. We are updating static variable outside its declaration because we cannot modify anything under proj1
. So please suggest some ways to update static variable from cprog1.c
file without modifying abc.h/Proj1
. If that is not possible suggest any workaround. Thanks.
Solutions already tried :
- Making
stvar
non static - not possible since we can not modifyabc.h
file - Using pointers - did not work