From: dennison@telepath.com
Subject: Re: Maybe not exactly a variant record.
Date: 1999/04/22
Date: 1999-04-22T00:00:00+00:00 [thread overview]
Message-ID: <7fo4ga$8pf$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 371f1e6d.0@silver.truman.edu
In article <371f1e6d.0@silver.truman.edu>,
"Josh Highley" <joshhighley@hotmail.com> wrote:
>
> I guess I should clarify. I'm not exactly sure the record is variant, at
> least not in the sense as some people have thought. So, here's the private
> declaration of "type field(length : positive);"
>
> private
> type field (length : positive ) is record
...
> text : string(1..length) := (others => ' ');
> text_length : natural := 0;
...
> end record;
>
> So, the value of "length" doesn't change the record fields that are
> accessible, just the number of characters in a string. Now that I've better
> described the situation, does this change the responses to declaring an
> array of type field with different lengths??
No it changes neither the responses, nor their rationale.
Assme you make an object of this type called "foo". If foo.length changes
from 4 to 5, suddenly foo.text(5) is available for you to access. If you don't
also assign a vaule to foo.text(5) when you assign a 5 to foo.length, then
there's uninitialized garbage sitting in foo.text(5).
What's worse, you could in theory try to hose the type of the .text_length
field by doing a foo.length := foo.length - 4. Depending on how your compiler
arranges the fields and implements the variant change, that could end up
putting the previous last 4 characters in foo.text into .text_length as an
integer!
Except of course this won't happen, because Ada won't allow you to change
foo.length w/o changing all of foo at the same time. :-)
> P.S. For my future reference, is the record that I've declared above
> considered a variant record, or is it called something else since the
> available record fields don't actually change with the value of "length"?
Yes, it is called a variant record, with "length" as the variant. Also the
available record fields *do* change, after a fashion. Incrementing foo.length
gives you an extra value in foo.text
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
next prev parent reply other threads:[~1999-04-22 0:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-20 0:00 Can I have an array of variant records? Josh Highley
1999-04-20 0:00 ` bglbv
1999-04-21 0:00 ` Robert Dewar
1999-04-21 0:00 ` Pawel Kobylarz
1999-04-21 0:00 ` David C. Hoos, Sr.
1999-04-21 0:00 ` Robert Dewar
1999-04-21 0:00 ` dennison
1999-04-21 0:00 ` Robert Dewar
1999-04-22 0:00 ` Josh Highley
1999-04-23 0:00 ` Pawel Kobylarz
1999-04-21 0:00 ` czgrr
1999-04-21 0:00 ` bglbv
1999-04-22 0:00 ` dennison
1999-04-21 0:00 ` Robert Dewar
1999-04-22 0:00 ` Maybe not exactly a variant record Josh Highley
1999-04-22 0:00 ` dennison [this message]
1999-04-23 0:00 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox