Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: effect of free() Message-ID: <11053@smoke.BRL.MIL> Date: 13 Sep 89 18:25:51 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> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article jdr+@andrew.cmu.edu (Jeff Rosenfeld) writes: -> Excerpts from netnews.comp.lang.c: 18-Aug-89 Re: effect of free() -> jourdan m. joseph@seti.i (1729) -> >bill@twwells.com (T. William Wells) writes: -> >> 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. -> You're wrong, Dick. Someone else already pointed it out, but let me -> make it clear again. ... -I can't believe this went so long without a response. Dick is correct; -@i[you] are mistaken, Jourdan. Keep in mind that pointers are stored in -memory just like any other data types and can be loaded into -general-purpose registers. No architecture of which I am aware does -protection checking when loading data into a general purpose register. I'm not sure the attributions are correct (this -> >> stuff gets confusing), but the very mention of "loading into a general-purpose register" implies a certain limited class of architectures. The discussion was about what MIGHT legally occur in a C implementation on SOME architecture. And it appears that it is legal for an implementation to get heartburn over continued access of a pointer (NOT just of what it presumably would point to) once the associated storage has been free()d.