home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!spool.mu.edu!caen!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: function name as an argument
- Message-ID: <1992Dec14.193634.5231@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1992Dec8.051134.5968@news.Hawaii.Edu> <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU>
- Date: Mon, 14 Dec 1992 19:36:34 GMT
- Lines: 49
-
- In article <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU>, adk@sun13.SCRI.FSU.EDU (Tony Kennedy) writes:
- |> >> J. Giles <jlg@cochiti.lanl.gov> and
- |> >> Steve Lionel <lionel@quark.enet.dec.com> write:
- |>
- |> lionel> PROGRAM DUMB
- |> lionel> character*10 func,arg
- |> lionel> external func
- |> lionel> call sub(func,arg)
- |> lionel> end
- |>
- |> lionel> SUBROUTINE SUB (func,arg)
- |> lionel> character*(*) func,arg
- |> lionel> arg = func()
- |> lionel> write(*,*)arg
- |> lionel> END
- |>
- |> lionel> FUNCTION FUNC()
- |> lionel> character*(*) func
- |> lionel> func = 'abcdefghijklmnopqrstuvwxyz'
- |> lionel> END
- |>
- |> [...]
- |>
- |> jlg> Nope, the space can be allocated statically when PROGRAM DUMB
- |> jlg> is compiled! The descriptor passed to SUB can contain the
- |> jlg> length of the space which has been allocated and a reference
- |> jlg> to that memory. This is the same information that needs to
- |> jlg> be passed if FUNC were called *directly* by the main program.
- |>
- |> This is not possible because the three routines can be compiled separately.
-
- It doesn't *matter* that they are compiled separately! The memory is
- allocated at compile time. It is allocated when the *main* program
- is compiled. The compiler needn't know or care what the size is
- or where the memory was allocated when compiling the subroutines.
- While compiling the subroutines, the compiler simply generates code
- which expects the main routine to *pass* this information implicitly
- in the calling sequence. This is exactly what it always does for
- character *variables*, why should it do any different for character
- *functions*? Where variables are concerned, this is exactly what the
- "CHARACTER*(*)" notation was designed to do.
-
- Once again: there is no need to rely on dynamic memory to provide
- the above functionality. However, it appears that there *is* a
- constraint in the Fortran 77 standard which prohibits it. I don't
- know why and neither does our representative to the committee.
-
- --
- J. Giles
-