1CALLOC(3P) POSIX Programmer's Manual CALLOC(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 calloc — a memory allocator
13
15 #include <stdlib.h>
16
17 void *calloc(size_t nelem, size_t elsize);
18
20 The functionality described on this reference page is aligned with the
21 ISO C standard. Any conflict between the requirements described here
22 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
23 defers to the ISO C standard.
24
25 The calloc() function shall allocate unused space for an array of nelem
26 elements each of whose size in bytes is elsize. The space shall be
27 initialized to all bits 0.
28
29 The order and contiguity of storage allocated by successive calls to
30 calloc() is unspecified. The pointer returned if the allocation suc‐
31 ceeds shall be suitably aligned so that it may be assigned to a pointer
32 to any type of object and then used to access such an object or an
33 array of such objects in the space allocated (until the space is
34 explicitly freed or reallocated). Each such allocation shall yield a
35 pointer to an object disjoint from any other object. The pointer
36 returned shall point to the start (lowest byte address) of the allo‐
37 cated space. If the space cannot be allocated, a null pointer shall be
38 returned. If the size of the space requested is 0, the behavior is
39 implementation-defined: either a null pointer shall be returned, or the
40 behavior shall be as if the size were some non-zero value, except that
41 the behavior is undefined if the returned pointer is used to access an
42 object.
43
45 Upon successful completion with both nelem and elsize non-zero, cal‐
46 loc() shall return a pointer to the allocated space. If either nelem or
47 elsize is 0, then either:
48
49 * A null pointer shall be returned and errno may be set to an imple‐
50 mentation-defined value, or
51
52 * A pointer to the allocated space shall be returned. The application
53 shall ensure that the pointer is not used to access an object.
54
55 Otherwise, it shall return a null pointer and set errno to indicate the
56 error.
57
59 The calloc() function shall fail if:
60
61 ENOMEM Insufficient memory is available.
62
63 The following sections are informative.
64
66 None.
67
69 There is now no requirement for the implementation to support the
70 inclusion of <malloc.h>.
71
73 None.
74
76 None.
77
79 free(), malloc(), realloc()
80
81 The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
82
84 Portions of this text are reprinted and reproduced in electronic form
85 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
86 table Operating System Interface (POSIX), The Open Group Base Specifi‐
87 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
88 Electrical and Electronics Engineers, Inc and The Open Group. In the
89 event of any discrepancy between this version and the original IEEE and
90 The Open Group Standard, the original IEEE and The Open Group Standard
91 is the referee document. The original Standard can be obtained online
92 at http://www.opengroup.org/unix/online.html .
93
94 Any typographical or formatting errors that appear in this page are
95 most likely to have been introduced during the conversion of the source
96 files to man page format. To report such errors, see https://www.ker‐
97 nel.org/doc/man-pages/reporting_bugs.html .
98
99
100
101IEEE/The Open Group 2017 CALLOC(3P)