Re: Proper way to return a string
- From: "Beliavsky" <beliavsky@xxxxxxx>
- Date: 29 Dec 2006 19:16:38 -0800
Ron Shepard wrote:
In article <2006122715420316807-gsande@worldnetattnet>,
Gordon Sande <g.sande@xxxxxxxxxxxxxxxx> wrote:
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". ;-)
Perhaps I misunderstand, but I think you have the same flexibility
with functions and subroutines. Since f77, both allow the result to
be declared as assumed length (i.e. (*), or in f90, (len=*)).
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
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.
.
- Follow-Ups:
- Re: Proper way to return a string
- From: Richard Maine
- Re: Proper way to return a string
- From: Ron Shepard
- Re: Proper way to return a string
- From: Walter Spector
- Re: Proper way to return a string
- From: Rich Townsend
- 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
- Re: Proper way to return a string
- From: Gordon Sande
- Re: Proper way to return a string
- From: Ron Shepard
- Proper way to return a string
- Prev by Date: Is there any problem with the following program?
- Next by Date: Re: Is there any problem with the following program?
- Previous by thread: Re: Proper way to return a string
- Next by thread: Re: Proper way to return a string
- Index(es):
Relevant Pages
|