Operating systems, development tools, and professional services
for connected embedded systems
for connected embedded systems
![]() |
![]() |
![]() |
![]() |
calloc()
Allocate space for an array
Synopsis:
#include <stdlib.h>
void* calloc ( size_t n,
size_t size );
Arguments:
- n
- The number of array elements to allocate.
- size
- The size, in bytes, of one array element.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The calloc() function allocates space from the heap for an array of n objects, each of size bytes, and initializes them to 0.
Returns:
A pointer to the start of the allocated memory, or NULL if an error occurred (errno is set).
Errors:
- ENOMEM
- Not enough memory.
- EOK
- No error.
Examples:
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
char* buffer;
buffer = (char* )calloc( 80, sizeof(char) );
if( buffer == NULL ) {
printf( "Can't allocate memory for buffer!\n" );
return EXIT_FAILURE;
}
free( buffer );
return EXIT_SUCCESS;
}
Classification:
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |
See also:
free(), malloc(), realloc(), sbrk()
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)
