Please enable JavaScript to view this site.

A-Shell Reference

++INCLUDE'ONCE <fspec>

This directive acts just like the regular ++INCLUDE, except that if the specified file has already been included in the current compilation, then it is skipped. This largely solves the problem—introduced by nesting—of accidentally including the same file twice. In fact, in most cases you may want to just use ++INCLUDE'ONCE all the time. It is somewhat unlikely that you would deliberately want to include the same file twice, but one possibility would be a set of map statements that you want to use locally within multiple functions.

To help you visually confirm the operation of skipping redundant ++INCLUDEs, the compiler will indicate them as in this example:

Phase 1 - Initial work memory is 16944 bytes

        Copying from ASHELL.DEF[907,16]

        Copying from SQL.DEF

        Copying from FNSQLCON.BSI

        Copying from FNSQLSTATE.BSI

        Skipping sql.def (already included)

          Copying from FNEXTCH.BSI[907,10]

        Copying from FNSQLATR.BSI

        ...

 

++INCLUDE'ONCE is useful for allowing individual modules to explicitly include their own dependent modules without having to know whether other modules in the program have already done so. But, it depends on using the option everywhere. An alternative or additional technique for avoiding including a module more than once, which does not rely on the consistent use of ++INCLUDE'ONCE, is to enclose each module inside a conditional compilation statement as follows:

! foo.bsi

++ifndef INC_FOO_BSI_

    define INC_FOO_BSI_ = 1 

 

    <contents of the module>

 

++endif

 

In the above example, the module is only included if the specified symbol is not yet defined. Since it gets defined immediately after the test, we can be sure that the contents of the module will only be included once. Although there is no enforced standard for the symbol names, to be practical, they need to be unique. Thus it is wise to form the symbol by appending some prefix and/or suffix to the module name.

See Also