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

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!walter!att-out!pacbell.com!decwrl!deccrl!news.crl.dec.com!dbased.nuo.dec.com!e2big.mko.dec.com!quark.enet.dec.com!lionel
  3. From: lionel@quark.enet.dec.com (Steve Lionel)
  4. Subject: Re: function name as an argument
  5. Message-ID: <1992Dec14.152401.18123@e2big.mko.dec.com>
  6. Lines: 65
  7. Sender: usenet@e2big.mko.dec.com (Mr. USENET)
  8. Reply-To: lionel@quark.enet.dec.com (Steve Lionel)
  9. Organization: Digital Equipment Corporation, Nashua NH
  10. References: <BURLEY.92Dec8185030@apple-gunkies.gnu.ai.mit.edu> <1992Dec10.012254.3535@alchemy.chem.utoronto.ca> <1992Dec10.155427.2271@e2big.mko.dec.com> <1992Dec12.010450.23241@draco.macsch.com>
  11. Date: Mon, 14 Dec 1992 15:24:01 GMT
  12.  
  13.  
  14. In article <1992Dec12.010450.23241@draco.macsch.com>, 
  15. dnl@convex.is.macsch.com (David Lombard) writes:
  16. |>In article <1992Dec10.155427.2271@e2big.mko.dec.com> lionel@quark.enet.dec.com (Steve Lionel) writes:
  17. |>>                                     Indeed, the standard says:
  18. |>>
  19. |>>    If a character function is referenced in a program unit,
  20. |>>    the function length specified in the program unit must be
  21. |>>    an integer constant expression.
  22. |>>
  23. |>>            ANSI X3.9-1978, section 15.2, p15-2, lines 5-7
  24. |>>
  25. |>>Because VAX FORTRAN supports the usage above, we always pass character
  26. |>>functions by descriptor, which includes the length.  But a standard-conforming
  27. |>>program can't do this thus a compiler which chooses not to support this
  28. |>>extension can get away without passing the length of character function
  29. |>>arguments.  (When the function is actually called, the length of the function
  30. |>>result does have to be passed, but that's another story.)
  31. |>>
  32. |>
  33. |>If you're going to quote the standard, make sure you're right.
  34.  
  35. Sage advice. I believe I followed it in this case.
  36.  
  37. |>
  38. |>See section 8.4.2 CHARACTER Type-Statement, line 46-:
  39. |>
  40. |>    If a dummy argument has a len of (*) declared, the dummy
  41. |>    argument assumes the length of the associated actual
  42. |>    argument for each reference of the subroutine or function.
  43. |>
  44. |>Thus, in a function or subroutine,
  45. |>
  46. |>    CHARACTER FRED*(*)
  47. |>
  48. |>is correct (IMHO the _proper_ declaration!).
  49. |>
  50.  
  51. Your own advice is probably appropriate here.  A careful reading of the
  52. paragraph you quote reveals that these lines only tell you what happens *IF*
  53. the dummy argument has a len of (*); it doesn't say that such a len is legal
  54. in this case.  If you keep reading to lines 5-10 on page 8-7, you'll see the
  55. additional rule that if the program unit references the function, the length
  56. must NOT be (*) but rather be an integer constant expression which "must
  57. agree with the length specified" in the actual function specification. (It
  58. was a restatement of the first part of this which also appeared in chapter
  59. 15 and which I quoted in the previous posting.) A length of (*) is legal, as 
  60. others have mentioned, only if the function is not referenced in the program 
  61. unit; perhaps it is passed as an argument to another routine. 
  62.  
  63. The Fortran language standard is not as explicitly written as that for some
  64. other languages (notably Ada), and there are times when the reader has to be
  65. familiar with the standard as a whole, fitting together pieces mentioned in
  66. diverse sections.  Even after many years of study, there are traps for the
  67. unwary and not a small number of ambiguities.   I've been in the Fortran
  68. business for over 14 years now, and I still find little surprises between
  69. the lines.  Don't feel too bad if it trips you up from time to time.
  70.  
  71. --
  72.  
  73. Steve Lionel                    lionel@quark.enet.dec.com
  74. SDT Languages Group
  75. Digital Equipment Corporation
  76. 110 Spit Brook Road
  77. Nashua, NH 03062
  78.