ABL electronic PIC12 Personal Computer User Manual


 
Structures
A structure is a derived type usually representing a user-defined collection of
named members (or components). The members can be of any type, either funda-
mental or derived (with some restrictions to be noted later), in any sequence. In
addition, a structure member can be a bit field type not allowed elsewhere.
Unlike arrays, structures are considered single objects. The mikroC structure type
lets you handle complex data structures almost as easily as single variables.
Note: mikroC does not support anonymous structures (ANSI divergence).
Structure Declaration and Initialization
Structures are declared using the keyword
struct:
struct
tag
{
member-declarator-list
};
Here,
tag
is the name of the structure;
member-declarator-list
is a list of
structure members, actually a list of variable declarations. Variables of structured
type are declared 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 a declared structure. Here is an example:
/* Structure defining a dot: */
struct Dot {float x, y;};
/* Structure defining a circle: */
struct Circle {
double r;
struct Dot center;
} o1, o2;
/* declare variables o1 and o2 of circle type */
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
74
MikroElektronika:
Development
tools
-
Books
-
Compilers
page