Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!uflorida!mailrus!cornell!batcomputer!lijewski From: lijewski@batcomputer.tn.cornell.edu (Mike Lijewski) Newsgroups: comp.lang.fortran Subject: passing subarrays to functions Keywords: F77 pass by value pass by reference Message-ID: <8378@batcomputer.tn.cornell.edu> Date: 12 Jul 89 16:12:02 GMT Distribution: comp Organization: Cornell National Supercomputer Facility Lines: 43 Consider the following program: program main dimension a(100) do 10 i = 1, 100 a(i) = 2.0 10 continue write(6,*) 'The sum is ', sum(a) write(6,*) 'The sum is ', sum(a(51)) end function sum(x) dimension x(50) temp = 0.0 do 10 i = 1, 50 temp = temp + x(i) 10 continue sum = temp end This produces: The sum is 100.0 The sum is 100.0 on each of an IBM 3090 using fortvs under both CMS and fvs under AIX, Sun 386i using SunOS f77 Version 4.0.1, and a Cray X-MP/48 using cft77 under UNICOS 4.0.8. My understanding was that since a(51) is a scalar it would be passed by reference and this code wouldn't work. Apparently though, a(51) is being resolve to the address of a(51). to see that it does work though. I used to think that you needed to equivalence a(51) to another array to do this kind of thing. What is the official F77 word on this type of construct? Mike Lijewski (H)607/277-7623 (W)607/255-0539 (desk)607/255-2960 Cornell National Supercomputer Facility ARPA: mjlx@cornellf.tn.cornell.edu BITNET: mjlx@cornellf.bitnet SMAIL: 102 E. Court St. Ithaca, NY 14850 -- Mike Lijewski (H)607/277-7623 (W)607/255-0539 (desk)607/255-2960 Cornell National Supercomputer Facility ARPA: mjlx@cornellf.tn.cornell.edu BITNET: mjlx@cornellf.bitnet SMAIL: 102 E. Court St. Ithaca, NY 14850