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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,48bf593f723b7524 X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Maybe not exactly a variant record. Date: 1999/04/22 Message-ID: <7fo4ga$8pf$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 469685898 References: <371c84fb.0@silver.truman.edu> <371f1e6d.0@silver.truman.edu> X-Http-Proxy: 1.0 x16.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Apr 22 21:31:54 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I) Date: 1999-04-22T00:00:00+00:00 List-Id: In article <371f1e6d.0@silver.truman.edu>, "Josh Highley" 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