Typedef Specifier
The specifier typedef
introduces a synonym for a specified type. The typedef
declarations are used to construct shorter or more convenient names for types already defined by the language or declared by the user.
The specifier typedef
stands first in the declaration:
typedef synonym as <type_definition>
The typedef
keyword assigns synonym
to <type_definition>
. The synonym
needs to be a valid identifier.
A declaration starting with the typedef
specifier 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 identifiers with starting capital letter — this is not required by the mikroBasic PRO for ARM.
For example:
' Let's declare a synonym for "word" typedef Distance as word ' Now, synonym "Distance" can be used as type identifier: 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”.
What do you think about this topic ? Send us feedback!