Link to home
Start Free TrialLog in
Avatar of roylam
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
ASKER CERTIFIED SOLUTION
Avatar of Iexpert
Iexpert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually, sounds more like a static local variable:

int SetValueAndReturnPrevious(int value)
{
    static int persistent = 0;

    int previous = persistent;
    persistent = value;
    return previous;
}
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;
}