From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: Ada 2005 box (<>) rules in default values
Date: Tue, 17 Jan 2006 21:15:31 GMT
Date: 2006-01-17T21:15:31+00:00 [thread overview]
Message-ID: <T7dzf.154158$dP1.512644@newsc.telia.net> (raw)
In-Reply-To: <43CCAB76.6050907@mailinator.com>
Alex R. Mosteo wrote:
> My understanding is that you use the <> value to denote the default
> value of a field in, for example a (limited or not) record:
>
> Blah : constant Thing :=
> (First_Component => 3,
> Second_Component => 4,
> others => <>);
>
> This actually compiles in GNAT GAP/GPL, but there's a thing happening
> that I don't know if it's that it isn't still completely implemented in
> Gnat, or is the expected behavior.
>
> Say, for example, that Thing above is declared like:
>
> type Thing is record
> First_Component : Integer;
> Second_Component : Integer;
> Third_Component : Integer := 5;
> end record;
>
> I'm finding that if I use the box as in the first example above, the
> third component will not receive its default value from the type
> definition (5), but will be uninitialized.
This appears to be corrected in GCC 4.0.2 on Gnu/Linux, as it passes the
test below. Alex, could you please compile this program and verify that
it triggers the bug in your environment? If not, you might want to post
a compilable test case that does display the error.
with Ada.Text_IO; use Ada.Text_IO;
procedure Uninitialized_Field_2005 is
type Thing is record
First_Component : Integer;
Second_Component : Integer;
Third_Component : Integer := 5;
end record;
Blah : constant Thing :=
(First_Component => 3,
Second_Component => 4,
others => <>);
begin
if Blah.Third_Component = 5 then
Put("Passed");
else
Put("Failed");
end if;
Put_Line(": Blah.Third_Component = " &
Integer'Image(Blah.Third_Component));
end Uninitialized_Field_2005;
$ gnatmake -gnat05 uninitialized_field_2005.adb
gcc -c -gnat05 uninitialized_field_2005.adb
gnatbind -x uninitialized_field_2005.ali
gnatlink uninitialized_field_2005.ali
$ ./uninitialized_field_2005
Passed: Blah.Third_Component = 5
--
Bj�rn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
next prev parent reply other threads:[~2006-01-17 21:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-17 8:31 Ada 2005 box (<>) rules in default values Alex R. Mosteo
2006-01-17 9:35 ` Martin Dowie
2006-01-17 13:35 ` ME
2006-01-17 17:19 ` Pascal Obry
2006-01-17 20:25 ` Randy Brukardt
2006-01-17 20:29 ` Randy Brukardt
2006-01-17 21:15 ` Björn Persson [this message]
2006-01-18 11:04 ` Alex R. Mosteo
2006-01-18 14:09 ` Jean-Pierre Rosen
2006-01-18 15:59 ` Alex R. Mosteo
2006-01-18 21:54 ` Randy Brukardt
2006-01-19 9:19 ` Alex R. Mosteo
2006-01-18 21:32 ` Björn Persson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox