From: murphy@mips.COM (Mike Murphy)
Subject: Re: Initialization
Date: 14 Jun 90 19:37:57 GMT [thread overview]
Message-ID: <39390@mips.mips.COM> (raw)
In-Reply-To: 1957@sparko.gwu.edu
In article <1957@sparko.gwu.edu> mfeldman@seas.gwu.edu (Michael Feldman) writes:
>I don't remember having seen any discussion on the group about why other
>types cannot be default-initialized, e.g.
> type Little is range -10 .. 10 := 0;
>or
> type Vector is array (1..10) of float := (1..10 => 0.0);
>or even
> type Vector is array (integer range <>) of float := (others => 0.0);
I question how useful type initialization is given that we can easily
initialize variables, but I agree that it is an irregularity to only
allow it for record types. When I first read this question I thought,
yea, that should be easy to do. But then I thought of some complications.
To take your above example, suppose we later said:
subtype PosLittle is Little range 1..10;
p : PosLittle;
What is p initialized to?
If we implicitly initialize p to 0 we should raise constraint_error;
is that acceptable?
A related issue is initializing unconstrained arrays; either we limit
the initialization to the others clause, or we have situations like:
type Vector is array (integer range <>) of float :=
(0 => 0.0, others => 1.0);
v : Vector(1..10);
What happens here? Either we could raise constraint_error because there
is an initialization to a component outside the range of v, or we could
treat it like a variant part of a record that is not used and just ignore
that part of the initialization. Which brings up the fact that type
initialization is not free; it often requires building an implicit
procedure that the compiler calls to dynamically decide how to initialize
the object.
A last case is initializing access types; is anything other than "null"
a legal initial value, e.g.
type astring is access string := new string'("void");
a : astring(1..3); -- constraint_error?
-- Mike Murphy
-- UUCP: sun!decwrl!mips!murphy or murphy@mips.com
next prev parent reply other threads:[~1990-06-14 19:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1990-06-14 16:37 Initialization Michael Feldman
1990-06-14 17:38 ` Initialization Robert Firth
1990-06-14 22:28 ` Initialization Michael Feldman
1990-06-14 19:37 ` Mike Murphy [this message]
1990-06-14 22:43 ` Initialization Michael Feldman
-- strict thread matches above, loose matches on Subject: below --
1991-03-24 21:23 Pre-condition vs. Post-condition stt
1991-03-25 16:00 ` Arthur Evans
1991-03-25 17:05 ` Michael Feldman
1991-03-26 4:31 ` Jim Showalter
1991-03-26 10:21 ` Richard A. O'Keefe
1991-03-27 21:32 ` Initialization Paul Stachour
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox