Static Functions

 

Like static variables, a static function is private to the SPL source file. Only functions defined in the same SPL file as the static function have access to the static function. For example:

 

// myfun.spl

 

static statfun()

{

    return("myfun statfun");

}

 

myfun(x)

{

    local y;

 

    y = statfun();

 

    return(y);

}

 

// statfun.spl

 

statfun()

{

    return("statfun);

}

 

a = statfun();

b = myfun();

 

a == "statfun"

b == "myfun statfun"

 

The function statfun defined in statfun.spl is a standard global function. The function statfun defined in myfun.spl is hidden from all functions except those functions defined in myfun.spl. Within myfun.spl, the static definition of statfun overrides global definitions of the same name, if any.

 

A static function defined in an SPL file should come before any global or static function that uses it.