Re: Proper way to return a string
- From: Rich Townsend <rhdt@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Dec 2006 22:51:45 -0500
Beliavsky wrote:
Ron Shepard wrote:
In article <2006122715420316807-gsande@worldnetattnet>,
Gordon Sande <g.sande@xxxxxxxxxxxxxxxx> wrote:
Probably because for a character function you need to declare aPerhaps I misunderstand, but I think you have the same flexibility
fixed size but it can vary if you use a subroutine.
Assuming that you use Fortran character variables for "strings". ;-)
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.
This is why TRIM() can never be implemented in F77, despite the claims to the
contrary by certain c.l.f regulars. Ultimately, there is no way in F77 to return
a string from a routine whose length is not known when the routine is entered.
cheers,
Rich
.
- 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: Is there any problem with the following program?
- 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
|