BSD bzero() & NULL

Doug Gwyn gwyn at smoke.brl.mil
Fri Nov 16 05:27:51 AEST 1990


In article <AbEJW8e00VQfE4N0I3 at andrew.cmu.edu> jl57+ at andrew.cmu.edu (Jay Laefer) writes:
>I realize that the following assignments are equal:
>char *fred;
>fred = 0;
>fred = (char *)NULL;
>because the compiler is responsible for translating the zero bit pattern
>into its internal representation of NULL.

They are both valid ways to assign a null pointer value to "fred", but
NOT bacuse of anthing to do with all-zero bit patterns.  In fact both
0 and NULL is such contexts stand in for a null pointer constant, which
need not have an all-zero bit representation.  That's right -- the "0"
in the above code is NOT an integer, even though it "looks" like one.

>But, given that bzero() directly fills an area with zeros, can I assume
>that the following is equivalent to the above?
>bzero(fred, sizeof (char *))

No, indeed this would try to fill "fred" with zero bits, which may not
be the right way to represent a null pointer (it depends on the
implementation).



More information about the Comp.lang.c mailing list