Casting call

Guy Harris guy at sun.uucp
Sun May 26 06:13:47 AEST 1985


> The original problem was that NULL is a valid address under 4.{2,3},
> but (char *) -1 isn't. This is, of course, dependent on 4.2 and
> the VAX.

The accident of implementation that makes the result of casting NULL into a
pointer be a value that does point to a mapped portion of your address space
doesn't justify using (char *) -1 as a special sentinel value for pointers,
instead of NULL.  On PDP-11 UNIX, an accident of implementation makes the
result of casting -1 into a pointer point to a mapped *and* writable portion
of your address space.  On VAX System V Release 2 Version 2, on 3B System V
Release 2 Version Whatever-Gives-You-Demand-Paging, on Vax 4.2BSD As
Modified By John Bruner, on Sun UNIX, on CCI Power 5/20 UNIX, on VAX/VMS,
and on lots of other implementations, either the address space is set up so
that the result of casting NULL into a pointer does not point to a mapped
portion of your address space or you can ask that the address space be so
set up.

Moral: use the language the way it's supposed to be used, and you're better
off.

	Guy Harris



More information about the Comp.lang.c mailing list