home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4712 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.4 KB  |  84 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!usc!cs.utexas.edu!hermes.chpc.utexas.edu!michael
  3. From: michael@chpc.utexas.edu (Michael Lemke)
  4. Subject: Re: function name as an argument
  5. Message-ID: <1992Dec15.061743.20060@chpc.utexas.edu>
  6. Organization: The University of Texas System - CHPC
  7. References: <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU> <1992Dec14.193634.5231@newshost.lanl.gov> <1gj95eINNqgo@gap.caltech.edu>
  8. Date: Tue, 15 Dec 92 06:17:43 GMT
  9. Lines: 73
  10.  
  11. In article <1gj95eINNqgo@gap.caltech.edu> shepard@sampson.ccsf.caltech.edu (Ron Shepard) writes:
  12. >I believe that the following is standard f77.  
  13.  
  14.     I don't think so -- see below.
  15.  
  16. >Note that the character
  17. >function is declared as (*) in the main program, and is declared, and
  18. >called, with different *(CONSTANT) values from the two subroutines.
  19. >
  20. >It is apparently because of the requirement of *(CONSTANT) declaration
  21. >in the referencing subprogram that this can be done legally without
  22. >recourse to runtime memory allocation.
  23. >
  24. >      program dumb
  25. >      character*30 cvar
  26. >      character*(*) cfun
  27. >      external cfun
  28. >      cvar='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  29. >      call sub1( cvar, cfun )
  30. >      write(*,*) 'cvar=', cvar
  31. >      call sub2( cvar, cfun )
  32. >      write(*,*) 'cvar=', cvar
  33. >      stop
  34. >      end
  35. >
  36. >      subroutine sub1( cvar, cfun )
  37. >      character*10 cvar
  38. >      character*10 cfun
  39. >c     # cfun() returns a 10-character value here.
  40. >      cvar = cfun()
  41. >      return
  42. >      end
  43. >
  44. >      subroutine sub2( cvar, cfun )
  45. >      character*20 cvar
  46. >      character*20 cfun
  47. >c     # cfun() returns a 20-character value here.
  48. >      cvar = cfun()
  49. >      return
  50. >      end
  51. >
  52. >      function cfun
  53. >      character*(*) cfun
  54. >c     # assign a 30-character value, truncating as necessary.
  55. >      cfun = '123456789012345678901234567890'
  56. >      return
  57. >      end
  58. >
  59. >Upon execution on a couple of machines, I get:
  60. >
  61. >cvar=1234567890xxxxxxxxxxxxxxxxxxxx
  62. >cvar=12345678901234567890xxxxxxxxxx
  63. >
  64. >which is what I thought I should get according to the previous discussion
  65. >in this thread.  
  66. >
  67. >Are there any machines that give different results?
  68.  
  69.     Yes, VAX/VMS:
  70.  
  71. $ for x
  72. %FORT-F-ADJLENUSE, Passed length character name used in invalid context 
  73.      [CFUN] in module DUMB 
  74. %FORT-F-ENDNOOBJ, IO$DUC0:[MICHAEL]X.FOR;2 completed with 1 diagnostic - object 
  75. deleted
  76.  
  77. So what junky Fortran took this?
  78.  
  79. Michael
  80. -- 
  81. Michael Lemke
  82. Astronomy, UT Austin, Texas
  83. (michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
  84.