Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!mcsun!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.lang.c Subject: Are 0 pointers more valid than invalid pointers? (Re: effect of free()) Message-ID: <8385@boring.cwi.nl> Date: 9 Sep 89 01:36:25 GMT References: <246@ssp1.idca.tds.philips.nl> <192700004@eriador> Organization: CWI, Amsterdam Lines: 29 In article <192700004@eriador> andyj@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@cwi.nl BITNET/EARN: dik@mcvax