comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin D. Condic" <mcondic-nospam@quadruscorp.com>
Subject: Re: Learning Ada & a question
Date: 2000/04/11
Date: 2000-04-11T13:59:36+00:00	[thread overview]
Message-ID: <38F35993.7A84BF3F@quadruscorp.com> (raw)
In-Reply-To: 38F2E992.EDB2DCCE@interact.net.au

G wrote:
> 
> In C++ they have devised all these ingenious little techniques for
> getting more than one return value from a function.  I am just wrapping
> my mind around the notion of pass-by-reference with pointers and
> references.  I know that access types are a sort of pointer in Ada.  Can
> you do the same things in Ada ?  Do you need to when Procedures can be
> called just as easily as functions anyways and return as many things as
> you need ?  (I maybe didnt say that right).
> 
I think what you're asking is "Can functions in Ada have 'out'
parameters so that more than just the function result can be returned?"
The short answer is 'no'. C/C++ never developed the notion of a
"procedure" which does not return a single result and cannot be used in
an equation. They sort of tacked that on by creating void functions and
having you pass the address of parameters (or ref in C++).

If you need something that computes multiple values and returns multiple
results, the correct way to do that in Ada is with a procedure. You
can't use a procedure in an equation, specifically because it doesn't
return a single result. If for some reason (and those reasons are rare)
you need a function that returns a single result and then has side
effects on its parameters, there is something called "The Rosen Trick"
which you can find on www.adapower.com or on my web site. (See below). I
would *strongly* advise avoiding this as a general programming technique
since it violates the general intent of the language, but it does have
its place.

If you want to get multiple results for a calculation, the way to do it
is basically like this:

procedure Get_Three_Results (X, Y, Z : out Integer) is.....

...

Get_Three_Results (A, B, C) ;
K := A + B + C ;

.....


Hope this is helpful

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"I'd trade it all for just a little more"
    --  Charles Montgomery Burns, [4F10]
======================================================================




  parent reply	other threads:[~2000-04-11  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-11  0:00 Learning Ada & a question G
2000-04-11  0:00 ` Ehud Lamm
2000-04-11  0:00 ` Marin D. Condic [this message]
2000-04-11  0:00 ` Larry Kilgallen
2000-04-11  0:00 ` Robert A Duff
replies disabled

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