comp.lang.ada
 help / color / mirror / Atom feed
From: Victor Porton <porton@narod.ru>
Subject: Re: If a routine should return two results, how should it be done?
Date: Sat, 26 Jul 2014 21:57:38 +0300
Date: 2014-07-26T21:57:38+03:00	[thread overview]
Message-ID: <lr0tn4$d71$1@speranza.aioe.org> (raw)
In-Reply-To: c3ibpuFsm87U1@mid.individual.net

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

  reply	other threads:[~2014-07-26 18:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-26 18:00 If a routine should return two results, how should it be done? Victor Porton
2014-07-26 18:53 ` Niklas Holsti
2014-07-26 18:57   ` Victor Porton [this message]
2014-07-26 19:21     ` Peter Chapin
2014-07-26 19:37       ` Dan'l Miller
2014-07-26 20:10     ` Shark8
2014-07-26 20:42 ` Victor Porton
2014-07-26 20:44   ` Victor Porton
2014-07-27 11:59 ` anon
replies disabled

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