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