Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
STRUCTURES
A structure represents a heterogeneous set of elements. Each element is called a
member; the declaration of a structure type specifies a name and type for each
member. The syntax of a structure type declaration is
structure structname
dim member1 as type1
'...
dim membern as typen
end structure
where 
structname
is a valid identifier, each 
type
denotes a type, and each 
member
is a valid identifier. The scope of a member identifier is limited to the structure in
which it occurs, so you don’t have to worry about naming conflicts between member
identifiers and other variables.
For example, the following declaration creates a structure type called Dot:
structure Dot
dim x as float
dim y as float
end structure
Each 
Dot
contains two members: 
x
and 
y
coordinates; memory is allocated when
you instantiate the structure, like this:
dim m, n as Dot
This variable declaration creates two instances of 
Dot
, called 
m
and 
n
.
A member can be of the previously defined structure type. For example:
' Structure defining a circle:
structure Circle
dim radius as float
dim center as Dot
end structure
141
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5