Re: Proper way to return a string
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Wed, 27 Dec 2006 19:42:03 GMT
On 2006-12-27 15:21:38 -0400, kargl@xxxxxxxxxxxxxxxxxxxxxxxxxxxx (Steven G. Kargl) said:
In article <slrnep5g8k.3020.Jeremy@xxxxxxxxxxxxxxxxxxx>,
Jeremy <my-first-name@xxxxxxxxxx> writes:
I am wrapping (because I cannot find it already done, if you know of one that exists let me know!) libpq for PostgreSQL database access. A
function, PQresStatus returns a string version of the result status. In
returning this to Fortran, can I return it from a function call? Should
I? Should I use a subroutine, I know how to easily deal with giving
string information back that way.
I guess I am still trying to understand when I should use a function
and when I should use a subroutine with inout/out parameters.
The following is my opinion. I'm sure others here will prefer
a different set of rules.
For numeric and logical types, if the routine computes a *single*
result, then I use a function. The function can take zero or
more arguments. If more than one result is to be returned, then
I use a subroutine. The distinction gets blurred when one starts
to consider array operations where the result is an array. Is the
array a single result or is it a collection several individual
elements?
For strings, I always use subroutines. I don't remember why I
developed that habit. It is just something I do.
Probably because for a character function you need to declare a
fixed size but it can vary if you use a subroutine.
Assuming that you use Fortran character variables for "strings". ;-)
There are, of course, exceptions to the rules. Here, one should
provide good comments, so the exceptions are well understood.
In the end, one should develop a style and stick with it.
.
- Follow-Ups:
- Re: Proper way to return a string
- From: David Frank
- Re: Proper way to return a string
- From: David Frank
- Re: Proper way to return a string
- From: Ron Shepard
- Re: Proper way to return a string
- From: Steven G. Kargl
- Re: Proper way to return a string
- References:
- Proper way to return a string
- From: Jeremy
- Re: Proper way to return a string
- From: Steven G. Kargl
- Proper way to return a string
- Prev by Date: Re: Proper way to return a string
- Next by Date: Re: Proper way to return a string
- Previous by thread: Re: Proper way to return a string
- Next by thread: Re: Proper way to return a string
- Index(es):
Relevant Pages
|