English
Language : 

CC78K4 Datasheet, PDF (202/523 Pages) NEC – CC78K4 Ver.2.30 or Later, C Compiler Language
CHAPTER 10 LIBRARY FUNCTIONS
5-6 realloc
Utility Functions
FUNCTION
The memory function realloc reallocates a block of memory (namely, changes the size of the allocated memory).
HEADER
stdlib. h
FUNCTION PROTOTYPE
void *realloc (void *ptr, size_t size);
Function
realloc
Arguments
Return Value
ptr ... Pointer to the beginning
of block previously allocated
size ... New size to be given to
this block
• Pointer to the beginning of
the reallocated space if the
requested size is
reallocated
• Pointer to the beginning of
the allocated space if ptr is
a null pointer
• Null pointer if the requested
size is not reallocated or
“ptr” is not a null pointer
EXPLANATION
• The realloc function changes the size of the allocated space (before a break value) pointed to by ptr to that
specified by size.
• If the value of size is greater than the size of the allocated space, the contents of the allocated space up to
the original size will remain unchanged. The realloc function allocates only for the increased space. If the
value of size is less than the size of the allocated space, the function will free the reduced space of the
allocated space.
• If ptr is a null pointer, the realloc function will newly allocate a block of memory of the specified size (same as
malloc).
• If ptr does not point to the block of memory previously allocated or if no memory can be allocated, the function
executes nothing and returns a null pointer.
(Reallocation will be performed by setting the address of ptr plus the number of bytes specified by size as a
new break value.)
202
User’s Manual U15556EJ1V0UM