From: kst@thomsoft.com (Keith Thompson)
Subject: Re: To Initialise or not
Date: 1996/05/01
Date: 1996-05-01T00:00:00+00:00 [thread overview]
Message-ID: <Dqq1F9.CK3@thomsoft.com> (raw)
In-Reply-To: Dqp3HF.12t@world.std.com
In <Dqp3HF.12t@world.std.com> 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.
next prev parent reply other threads:[~1996-05-01 0:00 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-29 0:00 To Initialise or not Steve O'Neill
1996-04-29 0:00 ` Ken Garlington
1996-04-29 0:00 ` Robert Dewar
1996-04-30 0:00 ` Ken Garlington
1996-04-30 0:00 ` Robert A Duff
1996-04-30 0:00 ` Robert A Duff
1996-04-30 0:00 ` Ken Garlington
1996-04-30 0:00 ` Robert A Duff
1996-05-01 0:00 ` Keith Thompson [this message]
1996-05-01 0:00 ` Theodore E. Dennison
1996-05-01 0:00 ` Robert A Duff
1996-05-02 0:00 ` Michael F Brenner
1996-05-02 0:00 ` Robert A Duff
1996-05-04 0:00 ` Kevin D. Heatwole
1996-05-02 0:00 ` Theodore E. Dennison
1996-05-02 0:00 ` Robert A Duff
1996-05-02 0:00 ` Chris Warack <sys mgr>
1996-05-02 0:00 ` Robert A Duff
1996-05-06 0:00 ` Ken Garlington
1996-05-06 0:00 ` Ken Garlington
1996-05-07 0:00 ` Robert A Duff
1996-05-08 0:00 ` Ken Garlington
1996-05-08 0:00 ` Robert A Duff
1996-05-09 0:00 ` Ken Garlington
1996-05-09 0:00 ` Robert A Duff
1996-05-01 0:00 ` Dale Stanbrough
1996-05-02 0:00 ` Robert Dewar
1996-05-02 0:00 ` Robert A Duff
1996-05-02 0:00 ` Theodore E. Dennison
1996-05-01 0:00 ` Robert A Duff
1996-05-02 0:00 ` Keith Thompson
1996-05-03 0:00 ` Robert A Duff
1996-05-06 0:00 ` Ken Garlington
1996-05-06 0:00 ` Ken Garlington
1996-05-07 0:00 ` Robert A Duff
1996-05-08 0:00 ` Ken Garlington
1996-05-09 0:00 ` Robert A Duff
1996-05-10 0:00 ` Robert A Duff
1996-05-10 0:00 ` Ken Garlington
1996-05-10 0:00 ` Robert A Duff
1996-05-10 0:00 ` Ken Garlington
1996-05-11 0:00 ` David Kristola
1996-05-11 0:00 ` Robert A Duff
1996-05-11 0:00 ` Robert A Duff
1996-05-13 0:00 ` Ken Garlington
1996-05-13 0:00 ` Robert A Duff
1996-05-13 0:00 ` Ken Garlington
1996-05-13 0:00 ` Ken Garlington
1996-05-13 0:00 ` Robert A Duff
1996-05-13 0:00 ` Ken Garlington
1996-05-01 0:00 ` Patrick Richard Wibbeler
1996-05-06 0:00 ` Ken Garlington
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox