Re: Proper way to return a string
- From: Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 00:44:14 -0600
In article <1167448598.037577.155500@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"Beliavsky" <beliavsky@xxxxxxx> wrote:
I don't think a function have a character(len=*) RESULT . For example,
for the following code
module string_func_mod
implicit none
contains
subroutine str_sub(aa,bb)
character (len=*), intent(in) :: aa
character (len=*), intent(out) :: bb
bb = aa
end subroutine str_sub
!
function str_func(aa) result(bb)
character (len=*), intent(in) :: aa
character (len=*) :: bb
bb = aa
end function str_func
end module string_func_mod
g95 says
In file string_func.f90:10
function str_func(aa) result(bb)
1
Error: Internal function 'str_func' at (1) cannot be an assumed-length
CHARACTER
The following code is legal f90, and without the result(), it would
be legal f77:
function str_func(aa) result(bb)
character (len=*) :: bb
character (len=*), intent(in) :: aa
bb = aa
end function str_func
I don't know why your original code does not compile. I expect that
it is some subtle difference between module functions (which are f90
only) and external functions (which are common to both f77 and f90).
For a subroutine argument, the LEN of the character argument is the
same on output as on input, but for a function, the compiler would not
"know" what the LEN of a character (len=*) RESULT is.
The compiler "knows" the length of the function result the same way
it "knows" the length of the argument. Namely, it is determined by
the calling routine.
$.02 -Ron Shepard
.
- References:
- Proper way to return a string
- From: Jeremy
- Re: Proper way to return a string
- From: Steven G. Kargl
- Re: Proper way to return a string
- From: Gordon Sande
- Re: Proper way to return a string
- From: Ron Shepard
- Re: Proper way to return a string
- From: Beliavsky
- 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
|