Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!uhccux!munnari.oz.au!mimir!hugin!augean!sirius!nt!levels!ccdn From: CCDN@levels.sait.edu.au (DAVID NEWALL) Newsgroups: comp.lang.c Subject: Re: effect of free() Message-ID: <1465@levels.sait.edu.au> Date: 8 Sep 89 13:33:17 GMT References: <319@cubmol.BIO.COLUMBIA.EDU> <3756@buengc.BU.EDU> <1989Aug17.005548.745@twwells.com> <16022@vail.ICO.ISC.COM> <248@seti.inria.fr> Organization: Sth Australian Inst of Technology Lines: 25 jourdan@seti.inria.fr (jourdan martin joseph) writes: >In article <16022@vail.ICO.ISC.COM> rcd@ico.ISC.COM (Dick Dunn) writes: >>bill@twwells.com (T. William Wells) writes: >>> char *ptr; >>> ptr = malloc(1); >>> free(ptr); >>> if (ptr == 0) ... >>> >>> 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. > > merely loading the value of "ptr" in a register to test it against 0 will > cause a invalid-address trap. Why? Loading the value of a pointer is not the same as dereferencing that pointer? I can't see why you should get an invalid-address trap. In fact, a machine that *did* trap in such a case, would be decidedly unfriendly. David Newall Phone: +61 8 343 3160 Unix Systems Programmer Fax: +61 8 349 6939 Academic Computing Service E-mail: ccdn@levels.sait.oz.au SA Institute of Technology Post: The Levels, South Australia, 5095