User manual
216
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Typedef Specier
The specier typedef introduces a synonym for a specied type. The typedef declarations are used to construct
shorter or more convenient names for types already dened by the language or declared by the user.
The specier typedef stands rst in the declaration:
typedef synonym as <type_denition>
The typedef keyword assigns synonym to <type_denition>. The synonym needs to be a valid identier.
A declaration starting with the typedef specier does not introduce an object or a function of a given type, but rather
a new name for a given type. In other words, the typedef declaration is identical to a “normal” declaration, but instead
of objects, it declares types. It is a common practice to name custom type identiers with starting capital letter — this is
not required by the mikroBasic PRO for dsPIC.
For example:
‘ Let’s declare a synonym for “word”
typedef Distance as word
‘ Now, synonym “Distance” can be used as type identier:
dim i as Distance ‘ declare variable i of word
In the typedef declaration, as in any other declaration, several types can be declared at once. For example:
typedef ^Pti, Array[10] as byte
Here, Pti is a synonym for type “pointer to int”, and Array is a synonym for type “array of 10 byte elements”.
Type Qualiers
The type qualiers const and volatile are optional in declarations and do not actually affect the type of declared
object.
Qualier const
The qualier const implies that a declared object will not change its value during runtime. In declarations with the
const qualier all objects need to be initialized.
The mikroBasic PRO for dsPIC30/33 and PIC24 treats objects declared with the const qualier the same as literals
or preprocessor constants. If the user tries to change an object declared with the const qualier compiler will report
an error.
For example:
const PI as byte = 3.14159