Please enable JavaScript to view this site.

A-Shell Development History

Individual global variables can now be declared as external (i.e. available for reference) within a function or procedure. (Previously your only choice was all or nothing, via the ++PRAGMA AUTO_EXTERN.) There are two methods, one to declare a block of variables, and one to declare individual variables...

To declare a block of variables as being visible within a function or procedure, use ++PRAGMA EXTERN_BEGIN and ++PRAGMA EXTERN_END:

++PRAGMA EXTERN_BEGIN

<repeat any number of global map statements here>

++PRAGMA EXTERN_END

 

The above approach is particularly useful when you want to ++INCLUDE a file containing a set of global map statements (perhaps a global control record).

To declare an individual variable as being visible within a function or procedure, use ++EXTERN in place of MAP, followed by the normal syntax for a MAP statement. For example:

++EXTERN GUIFLAGS,B,4

There are few subtleties and disclaimers to consider when using either of the above methods to declare specific global variables as being visible within a local procedure:

Declaring a variable with ++EXTERN or ++PRAGMA EXTERN_BEGIN does not have any effect on the original global variable definition, although it does allow the code within the procedure or function to modify the global variable at runtime.
The type and size may be omitted in the local extern declaration. Also, for arrays, the array dimensions may be omitted by just using (). However, if you do specify a type, size, or array dimensions, then they must match those in the original global definition of the variable. For example:

!(main program)

MAP1 GFLAGS(5),B,1

MAP1 SFLAG$,S,1

...

PROCEDURE TEST()

++EXTERN GFLAGS(5),B,1     ! valid

++EXTERN GFLAGS(5),F       ! invalid (types don't match)

++EXTERN GFLAGS(5),B,2     ! invalid (sizes don't match)

++EXTERN GFLAGS(4),B,1     ! invalid (subscripts don't match)

++EXTERN GFLAGS()          ! valid (equivalent to GFLAGS(5),B,1)

++EXTERN SFLAG$            ! valid (equivalent to SFLAG$,S,1)

 

The MAP level does not need to match (it doesn't even get specified for the ++EXTERN statements). But to the extent that there is any discrepancy between the local and global definitions, it is the global one that actually matters. The local one simply allows the local routine to access the global variable.