"Dan Pop" <Da*****@cern.c h> wrote in message
However, this should NOT be the criterion for choosing one or
another.
If your application needs zeroed memory, call calloc, otherwise call
malloc.
I would suggest malloc() followed by memset() for all occasions.
calloc() is a trap for the unwary, since floating point types and pointers
have all bits zero for 0.0 and NULL on almost all platforms, but this isn't
guaranteed.
Of course your application won't suffer from these problems, but another
programmer looking at the code will be surprised to see a call to calloc(),
and ask himself, "does the programmer who wrote this really know what he is
doing?".
In some environments it is a fairly common thing to trawl through code
looking for allocations. Searches for "malloc" and "realloc" are
unavoidable. If you have to search for "calloc" as well then it adds a layer
of difficulty no-one needs.
calloc() is a nuisance function that should be allowed to fall into disuse.
malloc() followed by memset() indicates your intention to allocate a chunk
of memory and initialise it to all bits zero.