Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 Manuale Utente

Codici prodotto
SW006021-1
Pagina di 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 157
Note that the const array does not need initial values to be specified in this instance, 
see Section 5.4.7.1 “Const Type Qualifier” and can reside over the top of other 
objects at these addresses.
If the pointer has to access objects in data memory, you need to define a different object 
to act as a dummy target. For example, if the checksum was to be calculated over 10 
bytes starting at address 0x90 in data memory, the following code could be used.
const char * cp;
char inputData[10] @ 0x90;
cp = &inputData;
// cp is incremented over inputData and used to read values there
User-defined absolute objects will not be cleared by the runtime startup code and can 
be placed over the top of other absolute variables.
Take care when comparing (subtracting) pointers. For example:
if(cp1 == cp2)
  ; // take appropriate action
The ANSI C standard only allows pointer comparisons when the two pointer targets are 
the same object. One exception is that the address may extend to one element past 
the end of an array.
Comparisons of pointers to integer constants are even more risky, for example:
if(cp1 == 0x246)
  ; // take appropriate action
Never compare pointers with integer constants.
A NULL pointer is the one instance where a constant value can be assigned to a pointer 
and this is handled correctly by the compiler. A NULL pointer is numerically equal to 0 
(zero), but this is a special case imposed by the ANSI C standard. Comparisons with 
the macro NULL are also allowed.
If NULL is the only value assigned to a pointer, the pointer will be made as small as 
possible.