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 03:20:11 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Disriminant question Date: Fri, 7 Mar 2003 11:20:10 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1047036010 12605 217.17.192.37 (7 Mar 2003 11:20:10 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Fri, 7 Mar 2003 11:20:10 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:35020 Date: 2003-03-07T11:20:10+00:00 List-Id: * tmoran@acm.org wrote: > If the type is declared with a default value for the discriminant, > and a particular object is declared with no discriminant specified, > then the object has the default value, and it can be replaced by > an aggregate assignment giving a new discriminant value and all the > fields appropriate to that value. That's interesting: $ cat t.adb with Ada.Text_IO; use Ada.Text_IO; procedure t is type DISC(some_disc : integer := 0) is record case some_disc is when 1 | 2 => int1, int2, int3 : integer; when others => flt : float; end case; end record; function f (i : Integer) return DISC is begin declare d : DISC(i); begin return d; end; end f; disk1 : DISC(1); disk3 : DISC(3); disk : DISC; begin Put_Line ("disk1'Size =" & Natural'Image (disk1'Size)); Put_Line ("disk3'Size =" & Natural'Image (disk3'Size)); disk := DISC'(some_disc => 1, others => 0); Put_Line ("disk'Size =" & Natural'Image (disk'Size)); disk := DISC'(some_disc => 3, others => 0.0); Put_Line ("disk'Size =" & Natural'Image (disk'Size)); for i in 1 .. 5 loop declare d : DISC(i); begin Put_Line ("d'Size =" & Natural'Image (d'Size)); end; end loop; for i in 1 .. 5 loop declare e : DISC := f (i); begin Put_Line ("e'Size =" & Natural'Image (e'Size)); end; end loop; end t; $ t disk1'Size = 128 disk3'Size = 64 disk'Size = 128 disk'Size = 128 d'Size = 128 d'Size = 128 d'Size = 64 d'Size = 64 d'Size = 64 e'Size = 128 e'Size = 128 e'Size = 128 e'Size = 128 e'Size = 128