home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!elroy.jpl.nasa.gov!nntp-server.caltech.edu!sampson!shepard
- From: shepard@sampson.ccsf.caltech.edu (Ron Shepard)
- Newsgroups: comp.lang.fortran
- Subject: Re: function name as an argument
- Date: 15 Dec 1992 00:33:50 GMT
- Organization: California Institute of Technology, Pasadena
- Lines: 55
- Message-ID: <1gj95eINNqgo@gap.caltech.edu>
- References: <1992Dec8.051134.5968@news.Hawaii.Edu> <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU> <1992Dec14.193634.5231@newshost.lanl.gov>
- NNTP-Posting-Host: sampson.ccsf.caltech.edu
-
- I believe that the following is standard f77. Note that the character
- function is declared as (*) in the main program, and is declared, and
- called, with different *(CONSTANT) values from the two subroutines.
-
- It is apparently because of the requirement of *(CONSTANT) declaration
- in the referencing subprogram that this can be done legally without
- recourse to runtime memory allocation.
-
- program dumb
- character*30 cvar
- character*(*) cfun
- external cfun
- cvar='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
- call sub1( cvar, cfun )
- write(*,*) 'cvar=', cvar
- call sub2( cvar, cfun )
- write(*,*) 'cvar=', cvar
- stop
- end
-
- subroutine sub1( cvar, cfun )
- character*10 cvar
- character*10 cfun
- c # cfun() returns a 10-character value here.
- cvar = cfun()
- return
- end
-
- subroutine sub2( cvar, cfun )
- character*20 cvar
- character*20 cfun
- c # cfun() returns a 20-character value here.
- cvar = cfun()
- return
- end
-
- function cfun
- character*(*) cfun
- c # assign a 30-character value, truncating as necessary.
- cfun = '123456789012345678901234567890'
- return
- end
-
- Upon execution on a couple of machines, I get:
-
- cvar=1234567890xxxxxxxxxxxxxxxxxxxx
- cvar=12345678901234567890xxxxxxxxxx
-
- which is what I thought I should get according to the previous discussion
- in this thread.
-
- Are there any machines that give different results?
-
- -Ron Shepard
- shepard@tcg.anl.gov
-