comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Learning Ada & a question
Date: 2000/04/11
Date: 2000-04-11T00:00:00+00:00	[thread overview]
Message-ID: <wccwvm4iuzg.fsf@world.std.com> (raw)
In-Reply-To: 38F2E992.EDB2DCCE@interact.net.au

G <gmw@interact.net.au> writes:

> 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).

Yes, you can pass access values as parameters in Ada.  If you want the
thing to return two different values, it's usually better to make it a
procedure with 'in out' or 'out' parameters, rather than a function with
a result and an access-value parameter.  You can do the same in C++; a
void-returning function is essentially the same thing as an Ada
procedure.  Except that C++ doesn't have 'in out'; you have to pass
pointers or references.

Or, if the two values are really part of a single conceptual "thing",
then you can wrap them in a record, and return the record from the
function.  Same thing in C++; use a struct.

Or, if one of the things you're returning is an error code, consider
raising an exception instead.

Ada functions are not allowed to have 'in out' or 'out' parameters, by
the way.

- Bob




  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
2000-04-11  0:00 ` Robert A Duff [this message]
2000-04-11  0:00 ` Larry Kilgallen
replies disabled

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