comp.lang.ada
 help / color / mirror / Atom feed
From: Lutz Donnerhacke <lutz@iks-jena.de>
Subject: Re: Disriminant question
Date: Fri, 7 Mar 2003 11:20:10 +0000 (UTC)
Date: 2003-03-07T11:20:10+00:00	[thread overview]
Message-ID: <slrnb6h038.nt.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: qlY9a.381382$HN5.1626412@rwcrnsc51.ops.asp.att.net

* 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



  reply	other threads:[~2003-03-07 11:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-07  7:09 Disriminant question prashna
2003-03-07  8:01 ` tmoran
2003-03-07 11:20   ` Lutz Donnerhacke [this message]
2003-03-07 17:59     ` tmoran
2003-03-07 22:32       ` Lutz Donnerhacke
2003-03-07 11:17 ` Lutz Donnerhacke
2003-03-07 16:46   ` Matthew Heaney
2003-03-12  9:25     ` Disriminant question - Waiting desperately for solution :-( prashna
2003-03-12 16:12       ` Gautier
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox