beautypg.com

Zilog Z8F0130 User Manual

Page 266

background image

Using the ANSI C-Compiler

UM013037-1212

242

Zilog Developer Studio II – Z8 Encore!
User Manual

or far data, or, if the pointer is to const data, in ROM. The naming of these functions is
straightforward, as follows:

If

foo(void* p1,const void* p2)

is a standard library function taking parameters

pointing to the default memory space, then the following the following additional library
functions are defined:

f_f_foo(far void* p1, const far void* p2)

takes pointers to far (12-bit)

memory

f_n_foo(far void* p1, const near void* p2)

takes pointers to far (12-bit)

memory and near (8-bit) memory

f_r_foo(rom void* p1, const near void* p2)

takes pointers to far (12-bit)

memory and rom (read-only 16-bit) memory

n_f_foo(near void* p1, const far void* p2)

takes pointers to near (8-bit)

memory and far (12-bit) memory

n_n_foo(near void* p1, const near void* p2)

takes pointers near (8-bit)

memory

n_r_foo(near void* p1, const near void* p2)

takes pointers to near (8-

bit) memory and rom (read-only 16-bit) memory

There are no

r_X_foo()

variants, because the first parameter to

foo()

is not

const

.

foo

is

#defined

to either

n_n_foo

or

f_f_foo

depending on memory model, but the

unadorned

foo()

function still exists in the run-time library.

In most cases, the return type must be the type of one of the parameters. One special case
is the

malloc()

function, which takes only a

size_t

parameter. In addition to

mal-

loc()

, there is

an f_malloc()

, which allocates from far memory, and

n_malloc()

,

which allocates from near memory.

Finally, the standard format strings for

printf()

,

scanf()

and their variants are

enhanced by providing a syntax to specify that a pointer parameter points into near, far, or
rom memory:

"%Ns"

formats or reads a string in near memory.

"%Fs"

formats or reads a string in far memory.

"%Rs"

formats or reads a string in ROM memory.

"%Np"

formats a pointer to near memory.

"%Fp"

formats a pointer to far memory.

"%Rp"

formats a pointer to ROM memory.

"%Nn"

saves the number of characters generated so far to an integer in near memory.