From: Jeffrey Carter <spam@spam.com>
Subject: Re: why can't we declare unconstrained objects ?
Date: Sun, 12 Dec 2004 18:40:40 GMT
Date: 2004-12-12T18:40:40+00:00 [thread overview]
Message-ID: <Ig0vd.8865$yr1.4348@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <cpi27p$2ft$1@titan.btinternet.com>
Martin Dowie wrote:
> Michael Mounteney wrote:
>
>> type thing (what : Boolean) is
>
> Simply add a default to the discriminant and you can change it all you
> want at run-time (e.g. "what : Boolean := Boolean'First").
To be precise (and it sounds as if the OP needs this level of detail),
if a discriminated record type has defaults for all discriminants, then
you can declare an unconstrained object of the type by not specifying
the discriminants:
type R (D : Boolean := False) is record ...
V : R;
...
V := R'(D => True, ...);
However, if you declare objects with discriminants specified:
X : R (D => False);
then the object is constrained and the discriminant cannot be changed.
Also, you can only change the discriminant by assigning the entire record.
V.D := True; -- illegal
If you're interested in interpreting the same bit pattern as 2 different
types, this is not the mechanism Ada uses. Use Unchecked_Conversion instead.
--
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus
22
next prev parent reply other threads:[~2004-12-12 18:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-12 15:43 why can't we declare unconstrained objects ? Michael Mounteney
2004-12-12 17:39 ` Martin Krischik
2004-12-12 17:47 ` Dmitry A. Kazakov
2004-12-12 18:21 ` Martin Dowie
2004-12-12 18:40 ` Jeffrey Carter [this message]
2004-12-12 19:24 ` Dmitry A. Kazakov
2004-12-15 13:39 ` David Botton
2004-12-15 21:47 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox