Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!jdr+ From: jdr+@andrew.cmu.edu (Jeff Rosenfeld) Newsgroups: comp.lang.c Subject: Re: effect of free() Message-ID: Date: 14 Sep 89 07:18:28 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> , <11053@smoke.BRL.MIL> Organization: Carnegie Mellon, Pittsburgh, PA Lines: 36 In-Reply-To: <11053@smoke.BRL.MIL> > Excerpts from netnews.comp.lang.c: 13-Sep-89 Re: effect of free() Doug > Gwyn@smoke.BRL.MIL (1384) > 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. OK - then consider the following code fragment (no pointer/int flames, please - they're not relevant here): union pi { char *ptr; unsigned long num; } x; x.ptr = malloc(AMOUNT); if (x.ptr != NULL) free(x.ptr); foo(x.num); This is perfectly legal code (despite that x.num contains nothing of guaranteed usefulness) and any compiler that generates code that causes a seg fault on the call to foo() has some serious problems. If you accept the previous statement, then it follows that any architecture capable of supporting an implementation of C must be able to perform a test on an arbitrary pointer. The test operation might be implemented through GP registers or with memory operands or whatever. But it HAS to be doable if the architecture can support C. Of course, if the ANSI committee deems my example illegal then I guess it's time to find another language-of-choice. In the meantime, I'd appreciate if someone can prove by counter-example using any real or imagined architecture that my claim is bogus. - Jeff (fearing days of strongly-typed assemblers).