Static Variables

Discussion in 'C++' started by SoftEast, Apr 19, 2007.

  1. SoftEast

    SoftEast Guest

    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
    SoftEast, Apr 19, 2007
    #1
    1. Advertising

  2. 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
    Michael DOUBEZ, Apr 19, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    923
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,366
    Tony Morris
    Oct 19, 2004
  3. Neviton
    Replies:
    9
    Views:
    446
    Alf P. Steinbach
    Sep 17, 2007
  4. Martin Wells

    Static inline functions with static local variables

    Martin Wells, Oct 6, 2007, in forum: C Programming
    Replies:
    10
    Views:
    695
    Army1987
    Oct 8, 2007
  5. Hicham Mouline
    Replies:
    5
    Views:
    2,351
    James Kanze
    Dec 19, 2008
Loading...

Share This Page