beautypg.com

Realloc – Zilog Z8F0130 User Manual

Page 481

background image

UM013037-1212

realloc

Zilog Developer Studio II – Z8 Encore!

User Manual

457

Synopsis

#include

int rand(void)

Returns

A pseudorandom integer.

Example

int i;

srand(1001);

i=rand();

realloc

Changes the size of the object pointed to by ptr to the size specified by size. The contents
of the object are unchanged up to the lesser of the new and old sizes. If ptr is a null pointer,
the

realloc

function behaves similarly to the

malloc

function for the specified size.

Otherwise, if ptr does not match a pointer earlier returned by the

calloc

,

malloc

, or

realloc

function, or if the space has been deallocated by a call to the

free

or

realloc

function, the behavior is undefined. If the space cannot be allocated, the

realloc

func-

tion returns a null pointer and the object pointed to by ptr is unchanged. If size is zero, the

realloc

function returns a null pointer and, if ptr is not a null pointer, the object it points

to is freed.

Synopsis

#include

void *realloc(void *ptr, size_t size);

Returns

Returns a pointer to the start (lowest byte address) of the possibly moved object.

Example

char *buf;

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

buf=(char *) realloc(buf, 80*sizeof(char));

if(buf !=NULL)

/*success*/

else

/*fail*/