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

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cs.utexas.edu!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: <1992Dec11.204152.28787@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References: <1992Dec8.051134.5968@news.Hawaii.Edu> <1992Dec8.140008.20523@e2big.mko.dec.com> <BURLEY.92Dec8185030@apple-gunkies.gnu.ai.mit.edu> <1992Dec10.012254.3535@alchemy.chem.utoronto.ca> <1992Dec10.155427.2271@e2big.mko.dec.com>
  9. Date: Fri, 11 Dec 1992 20:41:52 GMT
  10. Lines: 55
  11.  
  12. In article <1992Dec10.155427.2271@e2big.mko.dec.com>, lionel@quark.enet.dec.com (Steve Lionel) writes:
  13. |> [...]
  14. |>        PROGRAM DUMB
  15. |>        character*10 func,arg
  16. |>        external func
  17. |>        call sub(func,arg)
  18. |>        end
  19. |> 
  20. |>        SUBROUTINE SUB (func,arg)
  21. |>        character*(*) func,arg       
  22. |>        arg = func()
  23. |>        write(*,*)arg
  24. |>        END
  25. |> 
  26. |>        FUNCTION FUNC()
  27. |>        character*(*) func
  28. |>        func = 'abcdefghijklmnopqrstuvwxyz'
  29. |>        END
  30. |> 
  31. |> How does SUB know how much to allocate for the function result of SUB?  This
  32. |> isn't known at compile time, so the length has to be passed in to SUB somehow
  33. |> so that SUB can allocate the space at run-time.  [...]
  34.  
  35. Nope, the space can be allocated statically when PROGRAM DUMB is compiled!
  36. The descriptor passed to SUB can contain the length of the space which has
  37. been allocated and a reference to that memory.  This is the same infor-
  38. mation that needs to be passed if FUNC were called *directly* by the
  39. main program.
  40.  
  41. |> [...]                                     Wait a minute, you say - that
  42. |> means Fortran has dynamic allocation!  [...]
  43.  
  44. No.  As I pointed out above,  the memory can be statically allocated by
  45. the main program.  In this case, 10 characters worth.
  46.  
  47. |. [...]                               Well, it would if this was a standard
  48. |> conforming usage, and it is what I was thinking of when I originally wrote
  49. |> that the length had to be passed, but I had forgotten that this is an 
  50. |> extension supported by VAX FORTRAN.  Indeed, the standard says:
  51. |> 
  52. |>     If a character function is referenced in a program unit,
  53. |>     the function length specified in the program unit must be
  54. |>     an integer constant expression.
  55. |> 
  56. |>             ANSI X3.9-1978, section 15.2, p15-2, lines 5-7
  57.  
  58. Because of this quote, it is clear that the construct is, strictly
  59. speaking, non-standard.  However, it can be supported easily and without
  60. dynamic memory.  I rather suspect that the committee might have intended
  61. that passed-in character functions be allowed and that this constraint
  62. was intended to require that the size - wherever it came from - should
  63. be statically determinable.
  64.  
  65. -- 
  66. J. Giles
  67.