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

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!spool.mu.edu!caen!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (J. Giles)
  4. Subject: Re: function name as an argument
  5. Message-ID: <1992Dec14.193634.5231@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References: <1992Dec8.051134.5968@news.Hawaii.Edu> <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU>
  9. Date: Mon, 14 Dec 1992 19:36:34 GMT
  10. Lines: 49
  11.  
  12. In article <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU>, adk@sun13.SCRI.FSU.EDU (Tony Kennedy) writes:
  13. |> >> J. Giles <jlg@cochiti.lanl.gov> and
  14. |> >> Steve Lionel <lionel@quark.enet.dec.com> write:
  15. |> 
  16. |>    lionel> PROGRAM DUMB
  17. |>    lionel> character*10 func,arg
  18. |>    lionel> external func
  19. |>    lionel> call sub(func,arg)
  20. |>    lionel> end
  21. |> 
  22. |>    lionel> SUBROUTINE SUB (func,arg)
  23. |>    lionel> character*(*) func,arg       
  24. |>    lionel> arg = func()
  25. |>    lionel> write(*,*)arg
  26. |>    lionel> END
  27. |> 
  28. |>    lionel> FUNCTION FUNC()
  29. |>    lionel> character*(*) func
  30. |>    lionel> func = 'abcdefghijklmnopqrstuvwxyz'
  31. |>    lionel> END
  32. |> 
  33. |> [...]
  34. |> 
  35. |>    jlg> Nope, the space can be allocated statically when PROGRAM DUMB
  36. |>    jlg> is compiled! The descriptor passed to SUB can contain the
  37. |>    jlg> length of the space which has been allocated and a reference
  38. |>    jlg> to that memory.  This is the same information that needs to
  39. |>    jlg> be passed if FUNC were called *directly* by the main program.
  40. |> 
  41. |> This is not possible because the three routines can be compiled separately.
  42.  
  43. It doesn't *matter* that they are compiled separately!  The memory is
  44. allocated at compile time.  It is allocated when the *main* program
  45. is compiled.  The compiler needn't know or care what the size is
  46. or where the memory was allocated when compiling the subroutines.
  47. While compiling the subroutines, the compiler simply generates code
  48. which expects the main routine to *pass* this information implicitly
  49. in the calling sequence.  This is exactly what it always does for
  50. character *variables*, why should it do any different for character
  51. *functions*?  Where variables are concerned, this is exactly what the
  52. "CHARACTER*(*)" notation was designed to do.
  53.  
  54. Once again: there is no need to rely on dynamic memory to provide
  55. the above functionality.  However, it appears that there *is* a
  56. constraint in the Fortran 77 standard which prohibits it.  I don't
  57. know why and neither does our representative to the committee.
  58.  
  59. -- 
  60. J. Giles
  61.