home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- 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
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: function name as an argument
- Message-ID: <1992Dec11.204152.28787@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- 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>
- Date: Fri, 11 Dec 1992 20:41:52 GMT
- Lines: 55
-
- In article <1992Dec10.155427.2271@e2big.mko.dec.com>, lionel@quark.enet.dec.com (Steve Lionel) writes:
- |> [...]
- |> PROGRAM DUMB
- |> character*10 func,arg
- |> external func
- |> call sub(func,arg)
- |> end
- |>
- |> SUBROUTINE SUB (func,arg)
- |> character*(*) func,arg
- |> arg = func()
- |> write(*,*)arg
- |> END
- |>
- |> FUNCTION FUNC()
- |> character*(*) func
- |> func = 'abcdefghijklmnopqrstuvwxyz'
- |> END
- |>
- |> How does SUB know how much to allocate for the function result of SUB? This
- |> isn't known at compile time, so the length has to be passed in to SUB somehow
- |> so that SUB can allocate the space at run-time. [...]
-
- Nope, the space can be allocated statically when PROGRAM DUMB is compiled!
- The descriptor passed to SUB can contain the length of the space which has
- been allocated and a reference to that memory. This is the same infor-
- mation that needs to be passed if FUNC were called *directly* by the
- main program.
-
- |> [...] Wait a minute, you say - that
- |> means Fortran has dynamic allocation! [...]
-
- No. As I pointed out above, the memory can be statically allocated by
- the main program. In this case, 10 characters worth.
-
- |. [...] Well, it would if this was a standard
- |> conforming usage, and it is what I was thinking of when I originally wrote
- |> that the length had to be passed, but I had forgotten that this is an
- |> extension supported by VAX FORTRAN. 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 of this quote, it is clear that the construct is, strictly
- speaking, non-standard. However, it can be supported easily and without
- dynamic memory. I rather suspect that the committee might have intended
- that passed-in character functions be allowed and that this constraint
- was intended to require that the size - wherever it came from - should
- be statically determinable.
-
- --
- J. Giles
-