ABL electronic PIC16 Personal Computer User Manual


 
Pointers
Pointers are special objects for holding (or “pointing to”) memory addresses. In C,
address of an object in memory can be obtained by means of unary operator &. To
reach the pointed object, we use indirection operator (
*) on a pointer.
A pointer of type “pointer to object of type” holds the address of (that is, points to)
an object of type. Since pointers are objects, you can have a pointer pointing to a
pointer (and so on). Other objects commonly pointed at include arrays, structures,
and unions.
A pointer to a function is best thought of as an address, usually in a code segment,
where that function’s executable code is stored; that is, the address to which con-
trol is transferred when that function is called.
Although pointers contain numbers with most of the characteristics of unsigned
integers, they have their own rules and restrictions for declarations, assignments,
conversions, and arithmetic. The examples in the next few sections illustrate these
rules and restrictions.
Note: Currently, mikroC does not support pointers to functions, but this feature
will be implemented in future versions.
Pointer Declarations
Pointers are declared same as any other variable, but with
* ahead of identifier.
Type at the beginning of declaration specifies the type of a pointed object. A point-
er must be declared as pointing to some particular type, even if that type is void,
which really means a pointer to anything. Pointers to
void are often called gener-
ic pointers, and are treated as pointers to char in mikroC.
If type is any predefined or user-defined type, including void, the declaration
type
*p;
/* Uninitialized pointer */
declares p to be of type “pointer to
type
”. All the scoping, duration, and visibility
rules apply to the p object just declared. You can view the declaration in this way:
if
*p is an object of
type
, then p has to be a pointer to such objects.
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
68
MikroElektronika:
Development
tools
-
Books
-
Compilers
page