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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,524c88695fa43591 X-Google-Attributes: gid103376,public From: "Marin D. Condic" Subject: Re: Learning Ada & a question Date: 2000/04/11 Message-ID: <38F35993.7A84BF3F@quadruscorp.com>#1/1 X-Deja-AN: 609649920 Content-Transfer-Encoding: 7bit References: <38F2E992.EDB2DCCE@interact.net.au> Organization: Quadrus Corporation X-Sender: "Marin D. Condic" (Unverified) X-Server-Date: 11 Apr 2000 13:59:36 GMT Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-04-11T13:59:36+00:00 List-Id: 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] ======================================================================