Start Back Next End
  
ZBasic Language Reference
137
ZBasic Microcontrollers
to be imported from the header file.  Identifiers to exclude may be specified by adding a dash prefix.  If the
identifiers are not legal ZBasic identifiers (under the prevailing “name style”) they must be enclosed in
double quotes.  If the optional <id-list> is present, only identifiers present in the list will be imported
along with any other identifiers (e.g. structures, classes, etc.) necessary for the specified identifiers.  If the
optional <id-list>  is omitted, all identifiers present in the header file will be imported, including
identifiers in other header files included by the specified header file.  Note that no error message will be
issued for specified identifiers that are not found in the header file.
If the <id-list> contains the special string "#all-define", all identifiers with numeric values created
in the imported header files with the #define directive will also be imported.  Alternately, specific individual
#define identifers may be imported by including "#<id>" in the <id-list>, e.g. "#foo".
In its simplest form, the <import-file> specification takes the form of the name of a header file in 
either absolute or relative form. If the header file is specified as a relative pathname (i.e. one that does
not begin at the root directory of a drive), the pathname is assumed to be relative to the directory
containing the module containing the #import directive.  The directory containing the imported header
file is automatically added to a list of directories to search for other included files but note, however, that
that search list addition is in effect only for that particular importation.  If one or more other directories are
needed in the include file search list for a particular importation they must be specified using the
#include_path directive (described in Section 3.13) prior to the occurrence of the related import
directive.  Note that on Window-based computers, forward slash and backslash can be used
interchangeably in both the #import directive and in the #include_path directive.
 
Examples
#import Private "ethernet.h" IPAddr
#import C "C:/projects/MatrixMath/MatrixMath.h"
Two useful variations of specifying the <import-file> are provided that may simplify the importing
process in some cases.  These alternate methods are triggered by specifying either an asterisk (*) or a
commercial at sign (@) in place of the header filename at the end of the pathname.  The two examples
below illustrate the syntax.
Examples
#import C "C:/projects/MatrixMath/@"
#import C "C:/projects/MatrixMath/*"
The first example, using the commercial at sign, is equivalent to specifying the import file as
C:/projects/MatrixMath/MatrixMath.h, i.e. it specifies the importation of the header file with the
same base name as the directory name immediately preceding the final slash.   Moreover, it has the
additional effect of adding all of the immediate subdirectories of the last-specified directory to the include
path for that importation.
The second example, using the asterisk, specifies the importation of all header files (*.h) residing in the
last-specified directory.  Moreover, it has the same additional effect as the commercial at sign form of
adding all of the immediate subdirectories of the last-specified directory to the include path for all of those
importations.
When an include file is imported, it is processed by the C preprocessor just as it is when the code is
actually compiled.  The include files may contain conditional sections that control what features are
available and, moreover, may require certain identifiers to be defined to control the configuration.  When
the preprocessor is invoked a the special identifiers ZBASIC_IMPORT and ZBASIC_APP are defined that
can be used to further control configuration.  In particular, you may add a conditional section in a central
include file to define the special configuration identifiers.  An example is shown below.
Previous page Top Next page