17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In this case the first i8 is converted to 16 bit, then the add is a 16 bit add and the second i8 is<br />

forced to 16 bit.<br />

A common C programming error is to do something like:<br />

i16 = i8 * 100;<br />

When the intent was:<br />

i16 = (long) i8 * 100;<br />

Remember that with unsigned ints (the default for this compiler) the values are never<br />

negative. For example 2-4 is 254 (in 8 bit). This means the following is an endless loop since i<br />

is never less than 0:<br />

int i;<br />

for( i=100; i>=0; i--)<br />

How can a constant data table be placed in ROM?<br />

The compiler has support for placing any data structure into the device ROM as a constant<br />

read-only element. Since the ROM and RAM data paths are separate in the PIC® , there are<br />

restrictions on how the data is accessed. For example, to place a 10 element BYTE array in<br />

ROM use:<br />

BYTE CONST TABLE [10]= {9,8,7,6,5,4,3,2,1,0};<br />

and to access the table use:<br />

x = TABLE [i];<br />

OR<br />

x = TABLE [5];<br />

BUT NOT<br />

ptr = &TABLE [i];<br />

In this case, a pointer to the table cannot be constructed.<br />

Similar constructs using CONST may be used with any data type including structures, longs and<br />

floats.<br />

Note that in the implementation of the above table, a function call is made when a table is<br />

accessed with a subscript that cannot be evaluated at compile time.<br />

354

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!