home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4707 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  2.0 KB

  1. Path: sparky!uunet!usc!elroy.jpl.nasa.gov!nntp-server.caltech.edu!sampson!shepard
  2. From: shepard@sampson.ccsf.caltech.edu (Ron Shepard)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: function name as an argument
  5. Date: 15 Dec 1992 00:33:50 GMT
  6. Organization: California Institute of Technology, Pasadena
  7. Lines: 55
  8. Message-ID: <1gj95eINNqgo@gap.caltech.edu>
  9. References: <1992Dec8.051134.5968@news.Hawaii.Edu> <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU> <1992Dec14.193634.5231@newshost.lanl.gov>
  10. NNTP-Posting-Host: sampson.ccsf.caltech.edu
  11.  
  12. I believe that the following is standard f77.  Note that the character
  13. function is declared as (*) in the main program, and is declared, and
  14. called, with different *(CONSTANT) values from the two subroutines.
  15.  
  16. It is apparently because of the requirement of *(CONSTANT) declaration
  17. in the referencing subprogram that this can be done legally without
  18. recourse to runtime memory allocation.
  19.  
  20.       program dumb
  21.       character*30 cvar
  22.       character*(*) cfun
  23.       external cfun
  24.       cvar='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  25.       call sub1( cvar, cfun )
  26.       write(*,*) 'cvar=', cvar
  27.       call sub2( cvar, cfun )
  28.       write(*,*) 'cvar=', cvar
  29.       stop
  30.       end
  31.  
  32.       subroutine sub1( cvar, cfun )
  33.       character*10 cvar
  34.       character*10 cfun
  35. c     # cfun() returns a 10-character value here.
  36.       cvar = cfun()
  37.       return
  38.       end
  39.  
  40.       subroutine sub2( cvar, cfun )
  41.       character*20 cvar
  42.       character*20 cfun
  43. c     # cfun() returns a 20-character value here.
  44.       cvar = cfun()
  45.       return
  46.       end
  47.  
  48.       function cfun
  49.       character*(*) cfun
  50. c     # assign a 30-character value, truncating as necessary.
  51.       cfun = '123456789012345678901234567890'
  52.       return
  53.       end
  54.  
  55. Upon execution on a couple of machines, I get:
  56.  
  57. cvar=1234567890xxxxxxxxxxxxxxxxxxxx
  58. cvar=12345678901234567890xxxxxxxxxx
  59.  
  60. which is what I thought I should get according to the previous discussion
  61. in this thread.  
  62.  
  63. Are there any machines that give different results?
  64.  
  65. -Ron Shepard
  66. shepard@tcg.anl.gov
  67.