EXTERN

Purpose:

Declares a global variable in a function.

Syntax:

EXTERN var1, var2, ..., varN

varN

-

One or more variable names.

Example:

// myfun.spl
myfun(x)
{
    local a;
    extern b;
 
    a = x;
    b = a * a;
}

 

a = 10;

b = 20;

 

myfun(2);

 

a == 10;

b == 4;

 

The SPL function myfun declares variable a as local and variable b as external or global. Thus, the global variable a is unaffected, but global variable b is assigned by myfun.

Example:

Global variables can be specified on a file basis.

 

// myfun1.spl
 
extern a = 10;
extern b = 20;
 
myfun1()
{
    return(b);
}
 
 
myfun2(x)
{
    a = x;
    b = a * a;
}

 

c1 = myfun1();

 

c1 == 20;

 

myfun2(5);

 

a == 5;

b == 25;

 

c2 = myfun1();

 

c2 == 25;

 

Variables a and b are global variables accessible to both functions myfun1 and myfun2.

 

Remarks:

If a variable is not declared in an SPL function, it is assumed to be local.

 

File based external variables are initialized when the SPL function is first loaded, whether automatically loaded or explicitly loaded.

 

The extern keyword is the same as the GLOBAL keyword.

 

See LOCAL to specify local variables in an SPL function.

 

See STATIC to define local variables that are persistent across SPL function calls.

See Also:

DEFVAR

GLOBAL

LOCAL

NONLOCAL

SETLOCALVARIABLE

SETVARIABLE

STATIC