Start Back Next End
  
ZBasic Language Reference
138
ZBasic Microcontrollers
#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
to access an external identifier that differs only in case from an existing ZBasic identifier.  One way to
resolve this type of problem (and identifier clashes generally) is to import the external identifiers into a
ZBasic namespace.  The downside of this solution is that the namespace prefix will need to be prepended
to all top-level imported identifiers when used in ZBasic code.  See section 3.27 describing namespaces
for more information on this topic.
The third important issue arises when imported names are not legal ZBasic identifiers.  This can arise, for
example, because C/C++ identifiers must begin with an alphabetic character or an underscore and
contain only alphabetic, numeric and underscore characters.  Normally, a ZBasic identifier has the same
form except that it may not begin with an underscore.  To successfully import identifiers beginning with an
underscore you must ensure that the ZBasic compiler is using the C name style (which is now the default
setting).
The remaining important issue is related to importing C++ classes.  Normally, during the compilation
process the ZBasic compiler produces C code that is equivalent to the ZBasic code.  However, it is not
possible to access C++ classes, namespaces and other features specific to C++ code in C code.  The
solution to this is to direct the ZBasic compiler to produce C++ code instead of C code thus allowing
reference to the imported C++ elements.  This can be accomplished using either the Option CodeType
directive or the --code-type command line option.
As a final note, it is possible to specify files to be imported using the command line options --import
and --import-c, which options may appear in your project file.  The command line option for specifying
the include path to use while importing is --include-path.
Previous page Top Next page