Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Static Variables

Reply
Thread Tools

Static Variables

 
 
SoftEast
Guest
Posts: n/a
 
      04-19-2007
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

 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      04-19-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread safety problems with function scope static variables vs class static private members Hicham Mouline C++ 5 12-19-2008 08:10 PM
Static inline functions with static local variables Martin Wells C Programming 10 10-08-2007 03:38 PM
How can I access non-static variables from static funcition? Neviton C++ 9 09-17-2007 10:21 PM
Session Variables and Static Variables cobus.lombard@gmail.com ASP .Net 1 03-26-2006 11:05 AM
Instantiating a static class( Class with all static members - methods and variables) SaravanaKumar Java 6 10-19-2004 08:20 AM



Advertisments