Are 0 pointers more valid than invalid pointers? (Re: effect of free())

Dik T. Winter dik at cwi.nl
Sat Sep 9 11:36:25 AEST 1989


In article <192700004 at eriador> andyj at eriador.prime.com writes:
 >   3.  The Prime allows for dynamic linking.  This is accomplished by creating
 >       a "faulted" pointer, which is resolved to the actual object at run-time
 >       (if it exists).  Thus, a pointer must be "resolved" to its destination
 >       before it can be used in any operation (assignment, comparision, or
 >       dereference).  Any comparison with the faulted pointer will yield an
 >       incorrect result.  Note that the compiler makes a special check for
 >       comparison or assignment with a null pointer constant, since a null 
 >       pointer would give an addressing failure if it went through the special
 >       instructions.

Is this correct?  Given the following part of a program:
	int *a, *b;
	a = 0;
	b = 0;
	if (a == b) ....
If the above explanation states what I think it states this will trap.
Is this correct behaviour in ANSI C?  (There is no comparison with
constant 0 involved.)
An easy way out in this case is available on machines that have VM.
All invalid pointers are unmapped in user space, but NULL is mapped.
When a dereference of NULL occurs this will trap a page fault
the OS will see as a dereference of NULL.  So, completely according
to ANSI C, using an invalid pointer will trap, except when it is
NULL, than a trap only occurs on a dereference.
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik at cwi.nl
BITNET/EARN: dik at mcvax



More information about the Comp.lang.c mailing list