Re: NULL and zeros
- From: Christopher Layne <clayne@xxxxxxxxxxxx>
- Date: Tue, 03 Oct 2006 11:44:26 -0700
Richard Heathfield wrote:
You forgot to check the result of the malloc call before relying on it.
Alright, some stuff is implied, no need to bikeshed it.
2. The latter not result in a zero-filled struct?
Even assuming the calloc call succeeds (which is not a given), only those
members of the struct that are integer types are guaranteed to be given 0
values.
What? The entire space of the object is going to be set to 0. Since when does
memset() even care about integer types?
In most calloc()
implementations I've seen, they're just malloc() + memset().
And that's why. All calloc gives you is a block of memory with all-bits-zero
(for which memset is a fairly reasonable implementation technique). But
all-bits-zero doesn't necessarily mean "zero value", for pointer types and
floating point types.
Alright, and on that token, since we're getting fairly ridiculous by now - how
would all-bits-zero on said (funky machines) guarantee integer zero?
If a given machine expressed 0 as all 1s, then wouldn't supplying the value of
0 to memset result in it being set to all 1s?
.
- 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
- Re: NULL and zeros
- From: Christopher Layne
- Re: NULL and zeros
- From: Richard Heathfield
- NULL and zeros
- Prev by Date: Re: NULL and zeros
- Next by Date: Re: NULL and zeros
- Previous by thread: Re: NULL and zeros
- Next by thread: Re: NULL and zeros
- Index(es):
Relevant Pages
|