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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f298e2224380e530 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-07 08:46:11 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Disriminant question Date: 7 Mar 2003 08:46:10 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0303070846.252c6407@posting.google.com> References: NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1047055571 27765 127.0.0.1 (7 Mar 2003 16:46:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 7 Mar 2003 16:46:11 GMT Xref: archiver1.google.com comp.lang.ada:35039 Date: 2003-03-07T16:46:11+00:00 List-Id: Lutz Donnerhacke wrote in message news:... > * prashna wrote: > > How to change discriminant value dynamically? > > This is impossible. You can't change the discriminant, because the > instantiated variables does occupy different space. But you can set the > discriminant dynamically. The rule is that you can't change the discriminant if the object was declared with an explicit discriminant value. type RT (D : DT := DT'First) is record case D is when DT'First => null; when others => null; end case; end record; declare R1 : RT; --yes, can be changed R2 : RT := (D => DT'Last); --yes, can be changed R3 : RT (DT'First); --no, cannot be changed R4 : RT (DT'First) := (D => DT'First); --no, can't be changed begin R1 := (D => DT'Last); --OK R2 := (D => DT'First); --OK end; Basically, whenever you explicitly specify the discrimiant value in the declaration (i.e. the "subtype mark"), then that constrains the object, so that its discriminant cannot be changed. This allows the compiler to allocate only as much stack space as is needed for those components that apply to that discriminant value. Note that in the case of R3 and R4 above, it doesn't matter that the type has a default discriminant. The fact that the object was declared with an explicit value constrains the (sub)type.