ZBasic Language Reference
93
ZBasic Microcontrollers
End Sub
End Namespace
Sub Main()
Debug.Print foo::a
Call foo::SetVal(10)
Debug.Print foo::a
End Sub
Outside the namespace, references to entities defined in the namespace must be preceded by the
namespace prefix (the namespace name and a double colon) as seen in the Main() subroutine.
However, within the namespace itself the namespace prefix may be omitted.
It is important to note that the foo namespace could also have been written as shown below.
Namespace foo
Dim a as Integer
End Namespace
Namespace foo
Sub SetVal(ByVal v as Integer)
a = v
End Sub
End Namespace
Multiple occurrences of the same namespace are effectively aggregated into a single namespace
definition. Note, however, that the compiler will issue an error if the visibility of the namespace (i.e. Public
vs. Private) is not the same in all cases.
Although rarely necessary, it is permissible to place a namespace definition within a namespace
definition, such nesting allowed to an arbitrary depth. In such a case, namespace prefixes must be added
to identifiers beginning at the outer level and moving inward until the identifier itself is reached. For
example, foo::bar::myVar would be used (external to namespace foo) to refer to the variable myVar
defined within the namespace bar itself defined within the namespace foo.
One convenient use of a namespace is to include code in your application that was written by another
party where some of the identifiers used conflict with existing identifiers in your application. You can wrap
the other partys code in a namespace and eliminate identifier conflicts without otherwise changing the
code at the expense of having to use the namespace prefix to access the identifiers contained therein.
3.28 Data Type Implementation Information
This section provides more information on the technical details of the fundamental data types and
variants. Although this information is generally not needed to write properly functioning programs it is
provided for those who are interested and for the special cases where knowledge of such implementation
details may help you implement your application.
To review, the table of fundamental data types introduced earlier in this manual is reproduced here with
an additional column indicating the amount of space required for each type.
|