BSD bzero() & NULL

Chris Torek chris at mimsy.umd.edu
Thu Nov 15 23:42:37 AEST 1990


In article <AbEJW8e00VQfE4N0I3 at andrew.cmu.edu> jl57+ at andrew.cmu.edu
(Jay Laefer) asks:
>[does   char *fred; bzero((char *)&fred, sizeof fred)  put a nil pointer
  to char into `fred'?]
>My gut reaction is no because this zeros out a block of memory and I'm
>not guaranteed that the computer's internal representation of NULL is a
>zero bit pattern.

Your reaction is correct.  A fair amount of code (not just `BSD' code)
assumes that all nil pointers have zero bit patterns; this is one
reason the S1 project, which had tagged pointers and was going to use a
nonzero bit pattern for nil pointers, eventually gave up and
special-cased their C environment to allow all zero bits for nils:
it was more work to make things go fast than to make things go like
a {VAX, 68000, 80x86, ...}.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list