comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Out parameters and unconstrained variant types
Date: Thu, 26 Jun 2008 19:40:44 -0700 (PDT)
Date: 2008-06-26T19:40:44-07:00	[thread overview]
Message-ID: <ea46ffa4-0d65-41bd-8320-d7bbea820a59@u12g2000prd.googlegroups.com> (raw)
In-Reply-To: c6f8a097-4675-4335-bbda-ae552be2e8e6@m73g2000hsh.googlegroups.com

On Jun 26, 5:22 pm, Gene <gene.ress...@gmail.com> wrote:
> Hello friends,
>
> I would like to do something like:
>
> type Conditional_Result (Exists : Boolean := False) is
>   record case Exists is
>     when True =>
>       Value : Natural;
>     when False => null;
>   end record;
>
> procedure Do_Something(x : in Natural; rtn : out Conditional_Result)
> is
> begin
>   if x = 0 then
>     rtn := (Exists => False);
>   else
>     rtn := (Exists => True; Value => x + 1);
>   end if;
> end;
>
> procedure Foo is
>   rtn : Conditional_Result;
> begin
>   Do_Something(0, rtn);
>   if rtn.Exists then
>     Put_Line("Yes!");
>   end if;
>   Do_Something(1, rtn);
>   if rtn.Exists then
>     Put_Line("Yes!");
>   end if;
> end;
>
> ALRM 2005 and Barnes seem to say the procedure Do_Something will know
> that rtn in foo is unconstrained and allow both calls to succeed.  In
> GNAT 2007, the second call fails with a constraint error at the
> assignment to rtn.  Can you tell me what I'm missing?

It should work, and "anon" says he did get it to work with GNAT 2007.
But your example isn't a complete program, so perhaps if you post the
complete program you tried (assuming it's not much larger than this
example), maybe we can see something additional that you did that
would cause a problem.

                            -- Adam




  parent reply	other threads:[~2008-06-27  2:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27  0:22 Out parameters and unconstrained variant types Gene
2008-06-27  0:49 ` anon
2008-06-27  2:40 ` Adam Beneschan [this message]
2008-06-27  7:11 ` Georg Bauhaus
2008-06-27  7:58 ` Dmitry A. Kazakov
replies disabled

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