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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c1131ea1fcd630a X-Google-Attributes: gid103376,public From: kst@thomsoft.com (Keith Thompson) Subject: Re: To Initialise or not Date: 1996/05/01 Message-ID: #1/1 X-Deja-AN: 152405643 sender: news@thomsoft.com (USENET News Admin @flash) x-nntp-posting-host: pulsar references: <318508FE.204B@sanders.lockheed.com> <3184E9CE.5C7A@lmtas.lmco.com> <3185E379.7C20@lmtas.lmco.com> organization: Thomson Software Products, San Diego, CA, USA newsgroups: comp.lang.ada originator: kst@pulsar Date: 1996-05-01T00:00:00+00:00 List-Id: In bobduff@world.std.com (Robert A Duff) writes: [...] > No, sorry, I just meant the "if ... = null" as an *example*. The > general point is: If I explicitly initialize, then I plan to read that > value, at least in some cases. If I don't, then I promise I won't read > that value. [...] > In other words, pretend that you're coding in a language that's just > like Ada, except that there's no default initial value for pointers. > Write the code accordingly. Since this mythical language is a subset of > Ada, this is safe. I like the idea. The only problem is that the compiler won't help you enforce your promise not to read the value. An explicit ":= null" initialization is like a comment -- it's extremely useful, but it can get out of sync with the actual code. The real problem, I think, is that the access value null plays two different roles: as an uninitialized (garbage) value, and as a legitimate access value that doesn't designate any object. If I were designing a new language, I'd be tempted to define a second distinguished access value called, say, "invalid". The value null would act like it does in Ada: it doesn't point to anything and an attempt to dereference it raises Constraint_Error. The value invalid would be the default initial value of all access types; an attempt to dereference it *or to reference it* would raise Constraint_Error. For example: declare type Pointer_Type is access Some_Type; P1: Pointer_Type; -- implicitly initialized to invalid P2: Pointer_Type := null; P3: Pointer_Type; Obj: Some_Type; begin Obj := P1.all; -- raises Constraint_Error Obj := P2.all; -- raises Constraint_Error P3 := P2; -- ok, sets P3 to null P3 := P1; -- raises Constraint_Error end; The only cost would be a simple check on access assignments, which probably could be optimized out in most cases. Maybe for Ada 201Z? 8-)} -- Keith Thompson (The_Other_Keith) kst@thomsoft.com <*> TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718 This sig uses the word "Exon" in violation of the Communications Decency Act.