Variable Scope

The scope of a variable is the context within which it is defined. For the most part all ChaosPro variables only have a single scope. Variables in ChaosPro are either class local (i.e. global) or function local (i.e. can be used only within the function in which they have been defined).

  myformula  {  complex d;      void init(void)    {      z=d;    }  }  

Here the variable d will be available within the local function init. The variable d has been declared on class level and thus is known inside the whole class in every function.

However, within user-defined functions a local function scope is introduced. So you can define variables in this scope which will be only local variables to that function, thus they are created when the function is called and destroyed when the function returns.

  myformula  {  complex d;      void init(void)    {    real e;    real d;                e=4;    // references the local variable e      d=3;    // references the local variable d althoug there's a class local variable d              // function local variables have precedence over class local variables      z=e;    }    void loop(void)    {      z=d;    // d is a class local variable, the function local variable d is not existant.              // class local variable d has not been initialized, thus z is now undefined.    }  }  

Variable Scope