Re: Proper way to return a string
- From: "e p chandler" <epc8@xxxxxxxx>
- Date: 27 Dec 2006 20:19:52 -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=*)).
$.02 -Ron Shepard
As I understand it, a character(*) function returns a character
variable whose length is fixed by its caller. In the example below the
first program attempts to return a result of indeterminate length and
compilation fails. The second program does return a value which is then
truncated.
C:\g77>type foo1.f
character(*) zz
print *,'|',zz(),'|'
end
character(*) function zz()
zz='hello, world'
end
C:\g77>g77 foo1.f
foo1.f: In program `MAIN__':
foo1.f:1:
character(*) zz
1
foo1.f:3: (continued):
print *,'|',zz(),'|'
2
Invalid declaration of or reference to symbol `zz' at (2) [initially
seen at (1)
]
C:\g77>type foo2.f
character*10 zz
print *,'|',zz(),'|'
end
character(*) function zz()
zz='hello, world'
end
C:\g77>g77 foo2.f
C:\g77>a
|hello, wor|
C:\g77>
[I hope this rectifies my previous lack of understanding of this
subject. :-)]
e-mail: epc8 at juno dot com
.
- Follow-Ups:
- Re: Proper way to return a string
- From: Richard E Maine
- 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: Dimension attribute based on host-associated variable - bug in Intel Fortran
- Next by Date: General Subroutine Error
- Previous by thread: Re: Proper way to return a string
- Next by thread: Re: Proper way to return a string
- Index(es):
Relevant Pages
|
|