Pointer Types

There are two basic pointer types supported by the MPLAB XC8 C Compiler:

Data pointers
These hold the addresses of objects which can be read (and possibly written) by the program.
Function pointers
These hold the address of an executable function which can be called via the pointer.

These pointer types cannot be used interchangeably. Data pointers (even generic void * pointers) should never be used to hold the address of functions and function pointers should never be used to hold the address of objects.

The MPLAB XC8 compiler records all assignments of addresses to each pointer the program contains, and as a result, non-standard qualifiers are not required when defining pointer variables. The standard qualifiers const and volatile can still be used and have their usual meaning.

The size and format of the address held by each pointer is based on the set of all possible targets the pointer can address. This information is specific to each pointer defined in the program, thus two pointers with the same C type can hold addresses of different sizes and formats due to the way the pointers were used in the program.

The compiler tracks the memory location of all targets, as well as the size of all targets to determine the size and scope of a pointer. The size of a target is important as well, particularly with arrays or structures. It must be possible to increment a pointer so it can access all the elements of an array, for example.