Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: effect of free() Message-ID: <1989Aug18.185011.26836@utzoo.uucp> Organization: U of Toronto Zoology References: <319@cubmol.BIO.COLUMBIA.EDU> <3756@buengc.BU.EDU> <1989Aug17.005548.745@twwells.com> <16022@vail.ICO.ISC.COM> Date: Fri, 18 Aug 89 18:50:11 GMT In article <16022@vail.ICO.ISC.COM> rcd@ico.ISC.COM (Dick Dunn) writes: >> The if might cause a trap when the value of ptr is accessed. > >Not true. The "if" only examines the value of the pointer, not what it >points to. free(ptr) does not modify ptr; it can't. Assuming the malloc >succeeded ... the code as written will work... >The trouble will only begin when you try to look at *ptr. Dick, can you cite chapter and verse in X3J11 saying that it is legal to examine a pointer which points to freed storage? If not, I would say that you are making an implementation-dependent assumption. On some machines, pointers are very special animals, held in special registers that "know" that their contents are pointers, and loading a random value into such a register can cause trouble even if you don't dereference it. Whether any of them care about whether the pointer points to valid storage is another question. But it's not clear to me that such behavior is ruled out. -- V7 /bin/mail source: 554 lines.| Henry Spencer at U of Toronto Zoology 1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu