Static Variables

S

SoftEast

Can anybody elaborate if a technology doesn't support Static/Global
variables then what should be the logic behind it. I wanted to knoow
what extra h/w or memory contraints will it required to do so.

SoftEast
 
M

Michael DOUBEZ

SoftEast a écrit :
Can anybody elaborate if a technology doesn't support Static/Global
variables then what should be the logic behind it. I wanted to knoow
what extra h/w or memory contraints will it required to do so.

Any data persistence root must be allocated on the stack of the calling
function or one of its antecedant and pass by reference to functions
that use it (i.e. mutable data).
The simplest way do it is to implement all functions in a class and
then instanciate the class at the beginning of the program ('this' is
the implicite parameter). Looks really ugly but less than passing
explicitely by parameter.

struct program
{
int my_global;

void foo()
{
my_global=1;

bar();
}

void bar()
{
my_global=2;
}
}

int main()
{
program data;

data.foo();
}

Without those effort, you limit yourself to some kind of functional
programming (i.e. no state).


Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top