Re: NULL and zeros



Richard Heathfield wrote:

x = malloc (sizeof (MyType));
x->p = NULL;

more useful than

x = calloc (1, sizeof (MyType));

Neither is useful. The latter doesn't guarantee you a zero-filled struct,
and the first is unsafe.

How is,

1. The first unsafe? (presuming the rest of the members are explicitly
initialized as well)

2. The latter not result in a zero-filled struct? In most calloc()
implementations I've seen, they're just malloc() + memset().

Example:
total = num * size;
return ((mp = malloc(total)) ? memset(mp, 0, total) : mp);

.