Start Back Next End
  
ZBasic Language Reference
136
ZBasic Microcontrollers
#pragma StackUse( <stack-depth> )
An alternate syntax that can be used outside of all procedures, but not for ISRs, is shown below.
#pragma StackUse( <procedure-name>, <stack-depth> )
The recommended method used to generate an estimate of the stack use is to examine the assembly
listing file generated by the compiler in response to the –-list option (which also requires the –-keep-
files option) and manually compute the maximum stack depth.  Use of this method requires an
understanding of AVR assembly code and is therefore recommended for advanced users only.
6.7 Creating and Using Object Libraries
It is often useful to create a library of code elements from which the essential elements are drawn when
building an application.  Such libraries can then be easily reused in several applications or distributed to
other ZBasic users for use in building their applications. The ZBasic compiler supports the creation of
object libraries only for native mode devices.
To instruct the ZBasic compiler to build a library instead of building a downloadable file as it normally
does, add the option –-create-library to your project file.  If no filename is specified with that option,
the library name will be same as the project name but with the extension .a.  The compiler will create an
additional file containing ZBasic declarations for all of the public elements in the library; this file with have
the same name as the library but with the extension .inc.  It is important to note that none of the ZBasic
files compiled into the library should have a public subroutine named Main().
To use the library in a ZBasic application, it is only necessary to add the name of the declarations file to
that application’s project file or, alternately, to include the declarations file in one of your modules (e.g. the
Main() module) using the #include directive.  Generally, the declarations file and the library file should
be kept in the same directory.  The declarations file contains a directive to tell the compiler the name of
the corresponding library file – that’s why it doesn’t need to be explicitly mentioned.
If you create library files to distribute to others, you only need to supply the declarations file and the library
file.  The source code for the library needn’t be distributed if you’d like to keep it proprietary.
6.8 Importing Identifiers from External Modules
One of the benefits of using a native mode device is that your application can incorporate code written by
others even when code is not written in ZBasic.  This can be accomplished by incorporating pre-compiled
libraries or object files.  Alternately, it can be done by including C, C++, or assembly language source
code modules in your project.
The most direct way of providing access from ZBasic to variables, procedures, etc. in external modules is
to write Declare statements (as described in Section 6.2) for each of the items to which access is desired
from ZBasic.  While this method works in most cases (but not, for example, for external C++ classes) it
can be cumbersome and prone to error.  A more convenient method, one that also supports accessing
external C++ classes, is to import the definitions directly from an external header file (typically, a .h file).
The syntax importing a header file is given below.
#import [<lang-id>] [Public | Private] "<import-file>" [<id-list>]
The optional <lang-id> element may be either c or CPP (not case sensitive) to indicate the C and C++
languages, respectively.  If not specified, C++ is assumed.  Ordinarily, it will not be necessary to specify
the language.  However, if you have header files that are designed with one set of features to be available
when included in C code and a different set when included in C++ code you may wish to specify importing
the header file specifically as a C language header.
If neither Public nor Private is specified the importing is done privately meaning that all imported
identifiers will be private to the module.  The optional <id-list> is a comma-separated list of identifiers
Previous page Top Next page