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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8a7b744efabb21c4 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Out parameters and unconstrained variant types Reply-To: anon@anon.org (anon) References: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Fri, 27 Jun 2008 00:49:16 GMT NNTP-Posting-Host: 12.65.60.139 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1214527756 12.65.60.139 (Fri, 27 Jun 2008 00:49:16 GMT) NNTP-Posting-Date: Fri, 27 Jun 2008 00:49:16 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:898 Date: 2008-06-27T00:49:16+00:00 List-Id: -- -- Except for a few typos it work just fine in Ada 95 / 2005 -- using GNAT 3.15p and GNAT 2007 and 2008. -- with Ada.Text_IO ; use Ada.Text_IO ; procedure Foo is type Conditional_Result (Exists : Boolean := False) is record case Exists is when True => Value : Natural; when False => null; end case ; 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; 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!"); -- added to test value result. Put_Line("Value" & Integer'Image( rtn.Value) ); end if; end; In , Gene writes: >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!