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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: If a routine should return two results, how should it be done? Date: Sat, 26 Jul 2014 21:57:38 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: rFX7cZOSaeuGGZI2vwQTaQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21259 Date: 2014-07-26T21:57:38+03:00 List-Id: Niklas Holsti wrote: > On 14-07-26 21:00 , Victor Porton wrote: >> If a routine should return two results, how should it be done? > > Pick any method you like (but not case 2, if you want to be compatible > with pre-2012 Ada). > >> 1. procedure with two out arguments; >> >> 2. function with one out argument; >> >> 3. create specific record type for the result type of the function? >> >> What are advantages and disadvantages of each variant? > > The same as in any other language which offers these choices, which is > most languages (well, for C you must use pointers for "out" and "in > out", but logically it is the same thing). > > Oh, compared to C++ there is a small difference, in that Ada allows > overloading on the result type; in C++ one would perhaps avoid choices 3 > (and 2) for that reason. > > Personally I would first consider if the "two results" are logically > connected in such a way that they actually represent one composite > result, and then I would have a subprogram with one result -- no > problem. Otherwise, I would use choice 1. Choice 2 would be acceptable > to me only in very special cases, such as a random-number generator. I want to create a thick Ada binding for the following C function: http://librdf.org/raptor/api/raptor2-section-uri.html#raptor-uri-uri-string-to-filename-fragment char * raptor_uri_uri_string_to_filename_fragment (const unsigned char *uri_string, unsigned char **fragment_p); Which variant is better for this specific case: 1 or 3? -- Victor Porton - http://portonvictor.org