Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 50
 2012 Microchip Technology Inc.
3.4.3.3
HOW DO I PLACE VARIABLES IN PROGRAM MEMORY?
The const qualifier implies that the qualified variable is read only. As a consequence 
of this, any variables (except for auto variables or function parameters) qualified const 
are placed in program memory, thus freeing valuable data RAM, see Section 5.5.3 
“Variables in Program Space”
. Variables qualified const can also be made absolute, 
so that they can be positioned at an address you nominate, seSection 5.5.4.2 
“Absolute Objects in Program Memory”
.
3.4.3.4
HOW DO I STOP THE COMPILER USING CERTAIN MEMORY 
LOCATIONS?
Memory can be reserved when you build. The --RAM and --ROM options allow you to 
adjust the ranges of data and program memory, respectively, when you build. See 
Section 4.8.48 “--RAM: Adjust RAM Ranges” and Section 4.8.49 “--ROM: Adjust 
ROM Ranges”
. By default, all the available on-chip memory is available for use, but 
these options allow you to reserve parts of this memory.
3.4.4
Variables
This examines questions that relate to the definition and usage of variables and types 
within a program.
3.4.4.1
WHY ARE MY FLOATING-POINT RESULTS NOT QUITE WHAT I AM 
EXPECTING?
First, make sure that if you are watching floating-point variables in MPLAB IDE that the 
type and size of these match how they are defined. For 24-bit floating point variables 
(whether they have type float or double) ensure that the Format in the variable 
properties is set to IEEE float MPLAB IDE v8. In MPLAB X IDE set the Display Column 
Value As popup menu to IEEE float (24 bit). If the variable is a 32-bit floating point 
object, set the types to IEEE Float in both IDEs.
The size of the floating point type can be adjusted for both float and double types, 
see Section 4.8.31 “--FLOAT: Select Kind of Float Types” anSection 4.8.24 
“--DOUBLE: Select Kind of Double Types”
.
Since floating-point variables only have a finite number of bits to represent the values 
they are assigned, they will hold an approximation of their assigned value, see 
Section 5.4.3 “Floating-Point Data Types”. A floating-point variable can only hold 
one of a set of discrete real number values. If you attempt to assign a value that is not 
in this set, it is rounded to the nearest value. The more bits used by the mantissa in the 
floating-point variable, the more values can be exactly represented in the set and the 
average error due to the rounding is reduced.
Whenever floating-point arithmetic is performed, rounding also occurs. This can also 
lead to results that do not appear to be correct.