Page 141 of 229 Start Back Next End ZBasic Language Reference 131 ZBasic Microcontrollers 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. However, 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. #if defined(ZBASIC_IMPORT) // add necessary definitions here #endif It is important to be aware of several key issues related to importing. Firstly, importing a header file has the sole effect of making the imported identifiers available to the ZBasic code; it does not incorporate any of the code related to the include files in the application. You must add the names of the necessary source code files, object code files and/or object library files in order to make the necessary code become part of the application. The simplest way to include the actual external code is to specify the required external files (e.g. extension .c, .cpp, .o or .a) in your ZBasic project file. The second important issue to keep in mind is that, generally speaking, the identifiers in external files are case sensitive while identifiers in ZBasic are case insensitive. This can cause problems when you need