From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,345a8b767542016e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-16 23:25:24 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!elk.ncren.net!nntp.upenn.edu!msunews!not-for-mail From: "Chad R. Meiners" Newsgroups: comp.lang.ada Subject: Re: memory leakages with Ada? Date: Sun, 17 Mar 2002 02:22:47 -0500 Organization: Michigan State University Message-ID: References: <3c90af1e@news.starhub.net.sg> <3c91bfa3.1987537@news.demon.co.uk> <3C921A81.9060708@mail.com> Reply-To: "Chad R. Meiners" NNTP-Posting-Host: arctic.cse.msu.edu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Xref: archiver1.google.com comp.lang.ada:21357 Date: 2002-03-17T02:22:47-05:00 List-Id: "Kevin Cline" wrote in message > Dereferencing nil is just as fatal to program execution. The only advantage > is that it is more easily debugged because the crash is immediate. > Any code that keeps invalid pointers around, whether null or not, is > poorly crafted. Good programmers don't much care about the state > of a pointer variable after delallocation because the variable > is either going to be reassigned immediately or is going out of scope. While it is true that dereferencing a null pointer will raise a constraint_error exception, exceptions can be handled gracefully and null pointers can be guarded against. Pointers off to nowhere are very difficult to detect in a general manner. Your assertion about good programmers not caring about the state of a pointer, however, is false. For example, let's say we want to build a hash table of complex objects. This can be accomplished via an array of pointers to the given object type. Here is a case where we will want to reuse the pointers (although not necessarily immediately) since we might delete and add a bunch of objects throughout the program's lifetime. Here we can clearly use the state of the pointers to hold valuable information about the table. Is this use improper? No, this is actually a case where using pointers is the right way to go about solving the problem. Other examples of null pointers being useful are linked lists and tree data structures. This is one of the many reasons why I like Ada. The designers did a very good job with access types. I have never encountered a situation where I felt I was being forced by the language to use a pointer improperly in the six years I have been programming with it. I have found that Ada's design is embedded with much wisdom; if you ask, "Why does Ada do/have this?", the answer often makes you a better programmer. -CRM