roylam
asked on
permanent variable
i've a BIG program (open source) that is made up of many files what happen is that i want to have a variable that retain its value between different calls in that program.
ie. i just want to put a variable in a particular module which should retain its value from the previous call.
i'll charify more if this is not clear
ie. i just want to put a variable in a particular module which should retain its value from the previous call.
i'll charify more if this is not clear
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or, a different approach with a static global variable:
Module.c:
--------------
static int persistent = 0;
void SetValue(int value)
{
persistent = value;
}
int GetValue(void)
{
return persistent;
}
Module.c:
--------------
static int persistent = 0;
void SetValue(int value)
{
persistent = value;
}
int GetValue(void)
{
return persistent;
}
int SetValueAndReturnPrevious(
{
static int persistent = 0;
int previous = persistent;
persistent = value;
return previous;
}