beautypg.com

Malloc, Memchr, Malloc memchr – Zilog Z8F0130 User Manual

Page 472

background image

Appendix B. C Standard Library

UM013037-1212

448

Zilog Developer Studio II – Z8 Encore!
User Manual

Example

int i;

jmp_buf (env)

i=setjmp(env)

longjmp(env,i);

malloc

Allocates space for an object whose size is specified by

size

.

The existing implementation of

malloc()

depends on the heap area being located from

the bottom of the heap (referred to by the symbol __heapbot) to the top of the stack (SP).
Care must be taken to avoid holes in this memory range. Otherwise, the

malloc()

func-

tion might not be able to allocate a valid memory object.

Synopsis

#include

void *malloc(size_t size);

Returns

A pointer to the start (lowest byte address) of the allocated space. If the space cannot be
allocated, or if size is zero, the

malloc

function returns a null pointer.

Example

char *buf;

buf=(char *) malloc(40*sizeof(char));

if(buf !=NULL)

/*success*/

else

/*fail*/

memchr

Locates the first occurrence of c (converted to an

unsigned char

) in the initial n charac-

ters of the object pointed to by s.

Synopsis

#include

void *memchr(void *s, int c, size_t n);

Note: