Next: call_once
, Previous: cacosl
, Up: ISO C and POSIX Function Substitutes [Contents][Index]
calloc
POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html
Gnulib module: calloc-posix
Portability problems fixed by Gnulib:
errno
to ENOMEM
on
some platforms:
mingw, MSVC 14.
calloc (n, s)
can succeed even if
multiplying n
by s
would exceed PTRDIFF_MAX
or
SIZE_MAX
. Although failing to check for exceeding
PTRDIFF_MAX
is arguably allowed by POSIX it can lead to
undefined behavior later, so calloc-posix
does not allow
going over the limit.
Extension: Gnulib provides a module ‘calloc-gnu’ that substitutes a
calloc
implementation that behaves more like the glibc implementation.
It fixes this portability problem:
calloc (0, s)
and calloc (n, 0)
return NULL
on success
on some platforms:
AIX 7.2.