beautypg.com

Deviations from ansi c – Zilog Z8F0130 User Manual

Page 280

background image

Using the ANSI C-Compiler

UM013037-1212

256

Zilog Developer Studio II – Z8 Encore!
User Manual

extensions that are useful for developing embedded applications and for making efficient
use of the resources of the Z8 Encore! CPU. These extensions are described in the

Lan-

guage Extensions

section on page 194.

Deviations from ANSI C

The differences between the Zilog Z8 Encore! C-Compiler and the freestanding imple-
mentation of ANSI C Standard consist of both extensions to the ANSI standard and devia-
tions from the behavior described by the standard. The extensions to the ANSI standard
are explained in the

Language Extensions

section on page 194.

There are a small number of areas in which the Z8 Encore! C-Compiler does not behave as
specified by the standard. These areas are described in the following sections:

Prototype of Main

– see page 256

Double Treated as Float

– see page 257

const Keyword and ROM

– see page 257

Const Correctness in the Standard Header Files

– see page 258

ANSI Promotions Disabled

– see page 258

Library Files Not Required for Freestanding Implementation

– see page 258

Prototype of Main

As per ANSI C, in a freestanding environment, the name and type of the function called at
program start-up are implementation defined. Also, the effect of program termination is
implementation defined.

For compatibility with hosted applications, the Z8 Encore! C-Compiler uses

main()

as

the function called at program startup. Because the Z8 Encore! compiler provides a free-
standing execution environment, there are a few differences in the syntax for

main()

. The

most important of these is that, in a typical small embedded application,

main()

never

executes a return because there is no operating system for a value to be returned to and it is
also not intended to terminate. If

main()

does terminate and the standard Zilog Z8

Encore! C start-up module is in use, control simply goes to the following statement:

_exit:

JR _exit

For this reason, in the Z8 Encore! C-Compiler,

main()

must be of type

void

; any

returned value is ignored. Also,

main()

is not passed any arguments. In short, the follow-

ing is the prototype for

main()

:

void main (void);

Unlike the hosted environment in which the closest allowed form for main is as follows:

int main (void);