Type Specifier

The specifier type introduces a synonym for a specified type. The type declarations are used to construct shorter or more convenient names for types already defined by the language or declared by the user.

The specifier type stands first in the declaration:

type synonym = <type_definition>;

The type keyword assigns synonym to <type_definition>. The synonym needs to be a valid identifier.

A declaration starting with the type 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 type 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 mikroPascal PRO for 8051.

For example:

// Let's declare a synonym for "byte" 
type Distance = byte;

// Now, synonym "Distance" can be used as type identifier: 
var i : Distance ; // declare variable i of byte

In the type declaration, as in any other declaration, several types can be declared at once. For example:

type ^Pti, Array[10] = byte;

Here, Pti is a synonym for type “pointer to int”, and Array is a synonym for type “array of 10 int elements”.

Here is an example of declaring a synonym for volatile pointer in data space pointing to a byte in code space:

type ptrC = ^const code byte; data; volatile;

Now, synonym ptrC can be used as type identifier:

var ptr : ptrC; // declare variable ptr as volatile pointer in data space pointing to a byte in code space
Copyright (c) 2002-2013 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code