1CALLOC(P) POSIX Programmer's Manual CALLOC(P)
2
3
4
6 calloc - a memory allocator
7
9 #include <stdlib.h>
10
11 void *calloc(size_t nelem, size_t elsize);
12
13
15 The calloc() function shall allocate unused space for an array of nelem
16 elements each of whose size in bytes is elsize. The space shall be ini‐
17 tialized to all bits 0.
18
19 The order and contiguity of storage allocated by successive calls to
20 calloc() is unspecified. The pointer returned if the allocation suc‐
21 ceeds shall be suitably aligned so that it may be assigned to a pointer
22 to any type of object and then used to access such an object or an
23 array of such objects in the space allocated (until the space is
24 explicitly freed or reallocated). Each such allocation shall yield a
25 pointer to an object disjoint from any other object. The pointer
26 returned shall point to the start (lowest byte address) of the allo‐
27 cated space. If the space cannot be allocated, a null pointer shall be
28 returned. If the size of the space requested is 0, the behavior is
29 implementation-defined: the value returned shall be either a null
30 pointer or a unique pointer.
31
33 Upon successful completion with both nelem and elsize non-zero, cal‐
34 loc() shall return a pointer to the allocated space. If either nelem or
35 elsize is 0, then either a null pointer or a unique pointer value that
36 can be successfully passed to free() shall be returned. Otherwise, it
37 shall return a null pointer and set errno to indicate the error.
38
40 The calloc() function shall fail if:
41
42 ENOMEM Insufficient memory is available.
43
44
45 The following sections are informative.
46
48 None.
49
51 There is now no requirement for the implementation to support the
52 inclusion of <malloc.h>.
53
55 None.
56
58 None.
59
61 free() , malloc() , realloc() , the Base Definitions volume of
62 IEEE Std 1003.1-2001, <stdlib.h>
63
65 Portions of this text are reprinted and reproduced in electronic form
66 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
67 -- Portable Operating System Interface (POSIX), The Open Group Base
68 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
69 Electrical and Electronics Engineers, Inc and The Open Group. In the
70 event of any discrepancy between this version and the original IEEE and
71 The Open Group Standard, the original IEEE and The Open Group Standard
72 is the referee document. The original Standard can be obtained online
73 at http://www.opengroup.org/unix/online.html .
74
75
76
77IEEE/The Open Group 2003 CALLOC(P)