comp.lang.ada
 help / color / mirror / Atom feed
From: mfeldman@seas.gwu.edu (Michael Feldman)
Subject: Re: Initialization
Date: 14 Jun 90 22:43:50 GMT	[thread overview]
Message-ID: <1965@sparko.gwu.edu> (raw)
In-Reply-To: 39390@mips.mips.COM

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

  reply	other threads:[~1990-06-14 22:43 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 ` Initialization Mike Murphy
1990-06-14 22:43   ` Michael Feldman [this message]
  -- 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