Re: NULL and zeros
- From: Christopher Layne <clayne@xxxxxxxxxxxx>
- Date: Tue, 03 Oct 2006 11:35:35 -0700
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);
.
- Follow-Ups:
- Re: NULL and zeros
- From: Richard Heathfield
- Re: NULL and zeros
- References:
- NULL and zeros
- From: Yevgen Muntyan
- Re: NULL and zeros
- From: Eric Sosman
- Re: NULL and zeros
- From: Yevgen Muntyan
- Re: NULL and zeros
- From: Eric Sosman
- Re: NULL and zeros
- From: Yevgen Muntyan
- Re: NULL and zeros
- From: Christopher Layne
- Re: NULL and zeros
- From: Yevgen Muntyan
- Re: NULL and zeros
- From: Richard Heathfield
- NULL and zeros
- Prev by Date: Re: NULL and zeros
- Next by Date: Re: About Visual C++ 2005 Express Edition
- Previous by thread: Re: NULL and zeros
- Next by thread: Re: NULL and zeros
- Index(es):