Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Out parameters ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 5780 of 5874
Post > Topic >>

Out parameters and unconstrained variant types

by Gene <gene.ressler@[EMAIL PROTECTED] > Jun 26, 2008 at 05:22 PM

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?

Thanks!
 




 5 Posts in Topic:
Out parameters and unconstrained variant types
Gene <gene.ressler@[EM  2008-06-26 17:22:29 
Re: Out parameters and unconstrained variant types
anon@[EMAIL PROTECTED] (  2008-06-27 00:49:16 
Re: Out parameters and unconstrained variant types
Adam Beneschan <adam@[  2008-06-26 19:40:44 
Re: Out parameters and unconstrained variant types
Georg Bauhaus <rm.tsoh  2008-06-27 09:11:57 
Re: Out parameters and unconstrained variant types
"Dmitry A. Kazakov&q  2008-06-27 09:58:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 27 20:52:51 CDT 2008.