httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject Re: Use of pcalloc()
Date Sat, 19 Jul 1997 17:41:21 GMT
On Sat, 19 Jul 1997, Rodent of Unusual Size wrote:

> From the fingers of Alexei Kosut flowed the following:
> >
> >Hmm.
> >
> >I recently noticed something: The Apache code uses pcalloc() a lot to
> >allocate memory and initialize it, since pcalloc() (like its
> >similar-named calloc()) fills with zeros what it initializes. However,
> >isn't it illegal to assume that this will correctly make a structure's
> >members which are pointers null, since the null pointer is not
> >neccessarily represented by an all-bits zero pointer internally?
> 
>     Well, it's certainly no worse than using "if (!pointer)" to check
>     for a NULL value.

Yes, it is. (!pointer) is equal to (pointer != 0), and 0 is defined, in
pointer context, to be the null pointer. NULL is defined to be either 0
or (void *)0 (in ANSI C, at least). The null pointer, however, is not
defined to be anything, except a value that will never be used to point
to an actual area of memory. Many systems use the value 0 for this, but
not all.

So if the null pointer was, say, six, then (!pointer) would still work,
because 0 would be defined to be 6 (ain't C great?) in pointer
context. However, calloc() would still fill a structure with zero, which,
by way of not being equal to six, is not a null pointer.

I agree that it's not worth fixing, and no architecture that I know of
that is still around outside museums uses non-zero null pointers, but I
thought I'd point it out.

-- Alexei Kosut <akosut@organic.com>


Mime
View raw message