home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- 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
- From: lionel@quark.enet.dec.com (Steve Lionel)
- Subject: Re: function name as an argument
- Message-ID: <1992Dec14.152401.18123@e2big.mko.dec.com>
- Lines: 65
- Sender: usenet@e2big.mko.dec.com (Mr. USENET)
- Reply-To: lionel@quark.enet.dec.com (Steve Lionel)
- Organization: Digital Equipment Corporation, Nashua NH
- 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>
- Date: Mon, 14 Dec 1992 15:24:01 GMT
-
-
- In article <1992Dec12.010450.23241@draco.macsch.com>,
- dnl@convex.is.macsch.com (David Lombard) writes:
- |>In article <1992Dec10.155427.2271@e2big.mko.dec.com> lionel@quark.enet.dec.com (Steve Lionel) writes:
- |>> Indeed, the standard says:
- |>>
- |>> If a character function is referenced in a program unit,
- |>> the function length specified in the program unit must be
- |>> an integer constant expression.
- |>>
- |>> ANSI X3.9-1978, section 15.2, p15-2, lines 5-7
- |>>
- |>>Because VAX FORTRAN supports the usage above, we always pass character
- |>>functions by descriptor, which includes the length. But a standard-conforming
- |>>program can't do this thus a compiler which chooses not to support this
- |>>extension can get away without passing the length of character function
- |>>arguments. (When the function is actually called, the length of the function
- |>>result does have to be passed, but that's another story.)
- |>>
- |>
- |>If you're going to quote the standard, make sure you're right.
-
- Sage advice. I believe I followed it in this case.
-
- |>
- |>See section 8.4.2 CHARACTER Type-Statement, line 46-:
- |>
- |> If a dummy argument has a len of (*) declared, the dummy
- |> argument assumes the length of the associated actual
- |> argument for each reference of the subroutine or function.
- |>
- |>Thus, in a function or subroutine,
- |>
- |> CHARACTER FRED*(*)
- |>
- |>is correct (IMHO the _proper_ declaration!).
- |>
-
- Your own advice is probably appropriate here. A careful reading of the
- paragraph you quote reveals that these lines only tell you what happens *IF*
- the dummy argument has a len of (*); it doesn't say that such a len is legal
- in this case. If you keep reading to lines 5-10 on page 8-7, you'll see the
- additional rule that if the program unit references the function, the length
- must NOT be (*) but rather be an integer constant expression which "must
- agree with the length specified" in the actual function specification. (It
- was a restatement of the first part of this which also appeared in chapter
- 15 and which I quoted in the previous posting.) A length of (*) is legal, as
- others have mentioned, only if the function is not referenced in the program
- unit; perhaps it is passed as an argument to another routine.
-
- The Fortran language standard is not as explicitly written as that for some
- other languages (notably Ada), and there are times when the reader has to be
- familiar with the standard as a whole, fitting together pieces mentioned in
- diverse sections. Even after many years of study, there are traps for the
- unwary and not a small number of ambiguities. I've been in the Fortran
- business for over 14 years now, and I still find little surprises between
- the lines. Don't feel too bad if it trips you up from time to time.
-
- --
-
- Steve Lionel lionel@quark.enet.dec.com
- SDT Languages Group
- Digital Equipment Corporation
- 110 Spit Brook Road
- Nashua, NH 03062
-