global

Prev Next

Function Names

global

Synopsis

global { statements; }
global () statement;
global () { statements; }

Description

"ex In the statement or code block following the global function, all new variables defined are global variables. This ruling does not apply if a user function is called with that designated statement or code block, i.e. new variables created in the called user-defined functions are local functions. This ruling preents unexpected effects inside these user functions. The global variables are obviously retained if this function is called out from other user defined functions or program files.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

0

Examples

  d[] = 10; // Global variable defined outside the function

  define procedure ( foo )
  {
      a[] = 1;
      global
      {
          b[] = 2;
          a[c] = 3; // This one stays a local variable

          delete( d[] ); // If not in the global block, then exception happens.
      }
      echo( "Scope of b[] : ", scope( b[] ) ); // globa
      echo( "Scope of a[] : ", scope( a[] ) ); // local
      echo( "Scope of a[c]: ", scope( a[c]) ); // local
      echo( "Scope of d[] : ", scope( d[] ) ); // Not found.
  }

  foo;
  echo( "Global variable b[] = ", b[] );

Output

Scope of b[] : global
Scope of a[] : local
Scope of a[c]: local
Scope of d[] : not found
Global variable b[] = 2
Try it yourself: Open LIB_Function_global.b4p in B4P_Examples.zip. Decompress before use.

See also

local
regional