beautypg.com

In the, D in the, Library files – Zilog Z8F0130 User Manual

Page 282: Not required for freestanding implementation, Const correctness in the standard header files, Ansi promotions disabled

background image

Using the ANSI C-Compiler

UM013037-1212

258

Zilog Developer Studio II – Z8 Encore!
User Manual

Const Correctness in the Standard Header Files

In general, Zilog header files are not

const

correct due to the issue raised in the

const

Keyword and ROM

section on page 257. In the Zilog library, for example,

strcpy

is

(effectively) declared as:

char* strcpy( char* dst, char* src);

but the ANSI standard requires

char* strcpy( char* dst, const char* src);

As noted, this is done to avoid compile-time errors if the deprecated

const

variables in

ROM compilation option were selected and then

strcpy()

was called with an argument

for

src

that had not been declared

const

.

ANSI Promotions Disabled

The ANSI standard requires that integer variables smaller than

int

(such as

char

) always

be promoted to

int

before any computation.

The Z8 Encore! C-Compiler is ANSI compliant in this regard when ANSI promotions are
enabled. The C-Compiler analyzes and promotes variables smaller than

int

to

int

, only

where necessary to mimic the ANSI behavior.

As an example, for the following statement:

char ch1, ch2, ch3;

ch1 = ch2 * ch3;

The compiler does not promote

ch2

and

ch3

to

int

before the multiplication operation,

so the

char

result is not affected.

For the following statement:

char ch2, ch3;

int ii;


ii = ch2 * ch3;

The compiler promotes

ch2

and

ch3

to

int

before the multiplication operation, so the

result is of type

int

.

The Z8 Encore! C-Compiler also provides a deprecated option to disable ANSI promo-
tions. The ANSI behavior is not guaranteed when this option is selected, and Zilog does
not recommend using this option.

Library Files Not Required for Freestanding Implementation

As noted in the

Freestanding Implementation

section on page 255, only four of the stan-

dard library header files are required by the standard to be supported in a freestanding