User manual

mikroC PRO for dsPIC
MikroElektronika
213
Pointer Subtraction
Similar to addition, you can use operators -, -- , and -= to subtract an integral value from a pointer.
Also, you may subtract two pointers. The difference will be equal to the distance between two pointed addresses, in
bytes.
For example:
int a[10];
int *pi1 = &a[0];
int *pi2 = &a[4];
i = pi2 - pi1; /* i equals 8 */
pi2 -= (i >> 1); /* pi2 = pi2 - 4: pi2 now points to [0] */
Structures
A structure is a derived type usually representing a user-dened 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 addition, a structure member can be a bit eld.
Unlike arrays, structures are considered to be single objects. The mikroC PRO for dsPIC30/33 and PIC24 structure
type lets you handle complex data structures almost as easily as single variables.
The mikroC PRO for dsPIC30/33 and PIC24 supports anonymous structures.
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 following example:
struct mystruct {mystruct s;}; /* illegal! */
struct mystruct {mystruct *ps;}; /* OK */