beautypg.com

Double treated as float, Const keyword and rom – Zilog Z8F0130 User Manual

Page 281

background image

UM013037-1212

Deviations from ANSI C

Zilog Developer Studio II – Z8 Encore!

User Manual

257

Double Treated as Float

The Z8 Encore! C-Compiler does not support a double-precision floating-point type. The
type

double

is accepted but is treated as if it were

float

.

const Keyword and ROM

The Z8 Encore! C-Compiler by default assumes

const

in RAM and places

const

vari-

ables without any storage qualifications in RData for the small model and EData for the
large model. With the

const

in RAM option in affect, the C-Compiler follows the ANSI

C standard rules for

const

parameters.

However, the C-Compiler also provides a deprecated option to place such

const

variables

in ROM memory instead. When this option is selected, the treatment of the

const

key-

word is emphatically non-ANSI. Specifically, when this option is selected, the

const

key-

word is treated as equivalent to

rom

. Then, the function prototype

void foo (const char* src);

implies that the

src

string is in ROM memory, and any code that calls

foo

should pass

only a

const

or

rom

string as

src

string argument. This restriction comes because the Z8

Encore! microcontroller has different machine instructions for accessing its different
memory spaces (LDC, LD, and LDX). This is a deviation from ANSI C. The compiler
reports an “Incompatible data types” error for code that does not follow the preceding
restriction.

Under the ANSI standard, the

const

qualification on a parameter merely implies that the

function cannot modify the parameter and a non-

const

qualified argument can be passed

as the corresponding parameter.

The effect of this deviation from the standard is primarily that, in code that must be porta-
ble for all options of the compiler and linker (such as the source code for library functions
provided by the compiler), parameters cannot be declared

const

.

On new applications, Zilog discourages this use of the

const

keyword to place data in

ROM. Zilog recommends declaring constant data (such as tables) using the

rom

keyword

instead. Where portability is a consideration, this can easily be done by preprocessor mac-
ros.

For example:

#ifdef __EZ8__

# define ROM rom

#else

# define ROM const

#endif

ROM struct TableElement[] table = { /* stuff */};