Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site mako.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxb!mhuxn!mhuxm!mhuxj!houxm!vax135!cornell!uw-beaver!tektronix!orca!mako!jans From: jans@mako.UUCP (Jan Steinman) Newsgroups: net.lang Subject: Re: levelheight: automatic "nil pointer" handling: ENUF! Message-ID: <560@mako.UUCP> Date: Wed, 30-Jan-85 20:44:57 EST Article-I.D.: mako.560 Posted: Wed Jan 30 20:44:57 1985 Date-Received: Fri, 1-Feb-85 01:10:56 EST References: <2340@hplabsc.UUCP> <4948@utzoo.UUCP> <6292@boring.UUCP> <536@mako.UUCP> <6881@watdaisy.UUCP> Reply-To: jans@mako.UUCP (Jan Steinman) Distribution: net Organization: Tektronix, Wilsonville OR Lines: 53 <6881@watdaisy.UUCP> ndiamond@watdaisy.UUCP (Norman Diamond) writes, quotes: >>>For instance, it is possible to statically guarantee that nil pointers are >>>never dereferenced... >> >> Ada supports this: [quoted from Booch] > >The "answer" has nothing to do with the problem... All right, enough of you have told me I didn't understatnd the question. I don't think is is practical (possible?) to insure that null pointers will never be dereferenced at compile time. >The first netter's suggested problem was to diagnose programs that >dereference nil pointers. This... can be done dynamically. Ada has made this fairly easy to do. Simply put at the bottom of your code: exception when CONSTRAINT_ERROR => put("You probably dereferenced a pointer, jerk!); dumpPointers(); -- user supplied procedure. end; Unfortunately, the CONSTRAINT_ERROR exception also detects other things, such as array bounding, range constraints, etc. Perhaps a cleaner, more defensive posture is to isolate the exception handler to blocks which are capable of dereferencing a pointer, and somewhere near the top declare a special handler: -- In a high-level module: NULL_POINTER : exception; ... exception when NULL_POINTER => put("Now we know for sure you barfed a pointer!"); end; -- This block accesses an object through a pointer: begin -- dereference a pointer here... exception when CONSTRAINT_ERROR => raise NULL_POINTER; end; -- continue with non-pointer statements which may raise -- CONSTRAINT_ERROR, they will not effect NULL_POINTER exception. Somewhat clumsy, and a lot more keystrokes than "C", but it will do dynamic null dereferencing checking. I imagine there are even ways of making "C" do this. :-) -- :::::: Jan Steinman Box 1000, MS 61-161 (w)503/685-2843 :::::: :::::: tektronix!tekecs!jans Wilsonville, OR 97070 (h)503/657-7703 ::::::