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: Robert A Duff Subject: Re: Learning Ada & a question Date: 2000/04/11 Message-ID: #1/1 X-Deja-AN: 609656735 Sender: bobduff@world.std.com (Robert A Duff) References: <38F2E992.EDB2DCCE@interact.net.au> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-04-11T00:00:00+00:00 List-Id: G 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