beautypg.com

Malloc, Synopsis, Returns – Zilog ZUSBOPTS User Manual

Page 454: Example

background image

Standard Functions

UM017105-0511

426

Zilog Developer Studio II – ZNEO™
User Manual

Synopsis

#include

void longjmp(jmp_buf env, int val);

Returns

After

longjmp

is completed, program execution continues as if the corresponding call to

setjmp

had just returned the value specified by

val

. The

longjmp

function cannot cause

setjmp

to return the value 0; if val is 0,

setjmp

returns the value 1.

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*/

Note:

This manual is related to the following products: