Datasheet
STRUCTURES
A structure is a derived type usually representing a user-defined collection of named
members (or components). These members can be of any type, either fundamental
or derived (with some restrictions to be discussed later), in any sequence. In addi-
tion, a structure member can be a bit field.
Unlike arrays, structures are considered to be single objects. The mikroC PRO for
AVR structure type lets you handle complex data structures almost as easily as sin-
gle variables.
Note: the mikroC PRO for AVR does not support anonymous structures (ANSI diver-
gence).
Structure Declaration and Initialization
Structures are declared using the keyword struct:
struct tag {member-declarator-list};
Here, tag is the name of a structure; member-declarator-list is a list of structure
members, actually a list of variable declarations. Variables of structured type are
declared the same as variables of any other type.
The member type cannot be the same as the struct type being currently declared.
However, a member can be a pointer to the structure being declared, as in the fol-
lowing example:
struct mystruct {mystruct s;}; /* illegal! */
struct mystruct {mystruct *ps;}; /* OK */
Also, a structure can contain previously defined structure types when declaring an
instance of declared structure. Here is an example:
/* Structure defining a dot: */
struct Dot {float x, y;};
/* Structure defining a circle: */
struct Circle {
float r;
struct Dot center;
} o1, o2;
/* declare variables o1 and o2 of Circle */
165
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5