Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 26th, 2008, 07:40 PM
Gene
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Out parameters and unconstrained variant types

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!

Reply With Quote
  #2  
Old June 27th, 2008, 06:20 AM
Georg Bauhaus
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Out parameters and unconstrained variant types

Gene wrote:

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.

You can express your expectations in the program by adding

pragma Assert(not rtn'Constrained);


-- Georg

Reply With Quote
Reply

Viewing: Web Development Archives FAQs Programming > Out parameters and unconstrained variant types


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT