home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4679 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  1.8 KB

  1. Path: sparky!uunet!gatech!mailer.cc.fsu.edu!sun13!sun13.scri.fsu.edu!adk
  2. From: adk@sun13.SCRI.FSU.EDU (Tony Kennedy)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: function name as an argument
  5. Message-ID: <ADK.92Dec12114449@ds2.sun13.SCRI.FSU.EDU>
  6. Date: 12 Dec 92 16:44:49 GMT
  7. References: <1992Dec8.051134.5968@news.Hawaii.Edu>
  8.     <1992Dec8.140008.20523@e2big.mko.dec.com>
  9.     <BURLEY.92Dec8185030@apple-gunkies.gnu.ai.mit.edu>
  10.     <1992Dec10.012254.3535@alchemy.chem.utoronto.ca>
  11.     <1992Dec10.155427.2271@e2big.mko.dec.com>
  12.     <1992Dec11.204152.28787@new
  13. Sender: news@sun13.scri.fsu.edu
  14. Organization: SCRI, Florida State University
  15. Lines: 32
  16. In-reply-to: jlg@cochiti.lanl.gov's message of 11 Dec 92 20:41:52 GMT
  17.  
  18. >> J. Giles <jlg@cochiti.lanl.gov> and
  19. >> Steve Lionel <lionel@quark.enet.dec.com> write:
  20.  
  21.    lionel> PROGRAM DUMB
  22.    lionel> character*10 func,arg
  23.    lionel> external func
  24.    lionel> call sub(func,arg)
  25.    lionel> end
  26.  
  27.    lionel> SUBROUTINE SUB (func,arg)
  28.    lionel> character*(*) func,arg       
  29.    lionel> arg = func()
  30.    lionel> write(*,*)arg
  31.    lionel> END
  32.  
  33.    lionel> FUNCTION FUNC()
  34.    lionel> character*(*) func
  35.    lionel> func = 'abcdefghijklmnopqrstuvwxyz'
  36.    lionel> END
  37.  
  38.    lionel> How does SUB know how much to allocate for the function result
  39.    lionel> of SUB?  This isn't known at compile time, so the length has to
  40.    lionel> be passed in to SUB somehow so that SUB can allocate the space
  41.    lionel> at run-time.
  42.  
  43.    jlg> Nope, the space can be allocated statically when PROGRAM DUMB
  44.    jlg> is compiled! The descriptor passed to SUB can contain the
  45.    jlg> length of the space which has been allocated and a reference
  46.    jlg> to that memory.  This is the same information that needs to
  47.    jlg> be passed if FUNC were called *directly* by the main program.
  48.  
  49. This is not possible because the three routines can be compiled separately.
  50.