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, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada Subject: Re: Initialization Message-ID: <1965@sparko.gwu.edu> Date: 14 Jun 90 22:43:50 GMT References: <1957@sparko.gwu.edu> <39390@mips.mips.COM> Reply-To: mfeldman@seas.gwu.edu () Organization: The George Washington University, Washington D.C. List-Id: In article <39390@mips.mips.COM> murphy@mips.COM (Mike Murphy) writes: > > 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? Sure. Sounds OK to me. But you're right - the subtype issue does complicate matters a bit. > > 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); I'm sure a counterexample could be found, but I guess I would allow only "others" aggregates for unconstrained array types. Explicitly supplying an index for something whose index range is undefined is not a sensible thing to do, it seems to me. > [ . . . ] 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. Indeed. But there are many areas requiring this sort of dynamic decision anyway. > > 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"); Hmmm. I'd advocate against this kind of dynamic initialization even if it were a variable declaration. If Storage_Error were raised, for example, the exception would undoubtedly propagate to an undesirable place. (since it would be raised in an elaboration, the current frame's handler can't handle, therefore the exception propagates). Might be legal, but not a good idea. This is what I argued in my last posting: initializations can be good, but can be too powerful for their own good if used over-zealously. > a : astring(1..3); -- constraint_error? ^^^^^^^ Hmmm. I wasn't aware that one could supply a constraint this way. For a string, sure. For an "access to string", is this legal Ada (i.e. the implicit "new")? If so, I just learned a new style. Mike Feldman