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.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!mips!gumby!murphy From: murphy@mips.COM (Mike Murphy) Newsgroups: comp.lang.ada Subject: Re: Initialization Message-ID: <39390@mips.mips.COM> Date: 14 Jun 90 19:37:57 GMT References: <1957@sparko.gwu.edu> Sender: news@mips.COM Reply-To: murphy@mips.COM (Mike Murphy) Organization: MIPS Computer Systems, Sunnyvale, CA List-Id: 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