home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sgi / 13121 < prev    next >
Encoding:
Text File  |  1992-08-31  |  5.7 KB  |  155 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!sgiblab!sgigate!odin!bananapc.csd.sgi.com!ciemo
  3. From: ciemo@bananapc.csd.sgi.com (Dave Ciemiewicz)
  4. Subject: Re: Fortran problem on going from 4.0.1 to 4.0.5
  5. Message-ID: <1992Sep1.011508.15209@odin.corp.sgi.com>
  6. Sender: news@odin.corp.sgi.com (Net News)
  7. Nntp-Posting-Host: bananapc.csd.sgi.com
  8. Organization: Silicon Graphics, Customer Support Division
  9. References:  <1992Aug31.161432.1@vaxa.strath.ac.uk>
  10. Date: Tue, 1 Sep 1992 01:15:08 GMT
  11. Lines: 142
  12.  
  13. In article <1992Aug31.161432.1@vaxa.strath.ac.uk>, cbas25@vaxa.strath.ac.uk writes:
  14. |> The following fortran program illustrates a problem which has arisen on
  15. |> going from IRIX 4.0.1 to IRIX 4.0.5.
  16. |> When compiled under the first version of the operating system the program 
  17. |> works correctly, and gives the correct results from both subroutines
  18. |> (ONCE and DIFFER).  When compiled under 4.0.5 the program core-dumps at line
  19. |> 42, unless the compilation is done with the keyword '-static'. 
  20. |> 
  21. |> A cutdown version in which the subroutine 'ONCE' is not called and the 
  22. |> routine itself is not present, does run without core-dumping (when compiled 
  23. |> without '-static') but it appears that the numbers in the second array (XS)
  24. |> are not correctly held (all are either zero or very small numbers). 
  25. |> 
  26. |> My reading of the the Fortran manual pages leads me to believe that use
  27. |> of the 'SAVE' directive in the subroutine DIFFER is the only requirement
  28. |> for values to be retained on exit from a subroutine.
  29. |> 
  30.  
  31. I've done some perusing of the Fortran 77 ANSI Standard and have come to the
  32. conclusion that what you are attempting to do is not permitted by the standard.
  33. I'll provide you with the following references from both the SGI Fortran 77 
  34. manual and the Fortran 77 standard.  I'll also give you an technical
  35. explanation which explains why what you are trying to do should not work.
  36.  
  37. From the SGI Fortran Manual, (Document# 007-0710-040):
  38.  
  39.     Rules for Use:
  40.  
  41.     - A SAVE statement without a list is treated as though all
  42.       allowable entities from the program unit were specified on the list.
  43.  
  44.     ...
  45.  
  46.     Restrictions:
  47.  
  48.     Procedure names and dummy arguments cannot appear in a SAVE statement.
  49.  
  50. From the ANSI standard:
  51.  
  52.     8.9 Save Statement ...
  53.         Dummy argument names ... must not appear in a SAVE statement.
  54.  
  55.         A SAVE statement without a list is treated as though it
  56.         contained the names of all allowable itmes in that program
  57.         unit.
  58.         
  59.     15.6.3 ...
  60.         In a subroutine subprogram, the symbolic name of a dummy
  61.         argument cannot appear in a ... SAVE ... statement.
  62.  
  63.  
  64. Interpreting you example with respect to these statements:
  65.  
  66. |>       SUBROUTINE DIFFER
  67. |>       SAVE
  68. |>       DIMENSION XR(10)
  69. |>       DIMENSION XS(10)
  70. |>       ENTRY DIFF1 (XR)
  71. |>       RETURN
  72. |>       ENTRY DIFF2 (XS)
  73. |>       RETURN
  74. |>       ENTRY DIFF3 (I,J,D)
  75. |>       write (*,*) i,j,xr(i),xs(j)  !Program fails here when '-static' not used
  76. |>       D = XR(I) - XS(J)
  77. |>       RETURN
  78. |>       END 
  79.  
  80. XR and XS are dummy arguments for ENTRY DIFF1 and ENTRY DIFF2.  Since they
  81. are dummy arguments, they are not allowable in a SAVE statement, thus they
  82. will not be saved by the SAVE statement with an empty list.
  83.  
  84.  
  85. Further, reading of the ANSI standard yields the following:
  86.  
  87.     15.7.4 ENTRY statement Restrictions ...
  88.  
  89.     If a dummy argument appears in an executable statement, the
  90.     execution of the executable statement is permitted during the
  91.     execution of a reference to the function or subroutine only if
  92.     the dummy argument appears in the dummy aguement list of the
  93.     procedure name referenced.  Note that the association of dummy
  94.     arguments is not retuained between references to a function or
  95.     subroutine.
  96.  
  97. Looking at your above example, XR is only valid when DIFF1 is called and
  98. XS is only valid when DIFF2 is called.  Your use of XR and XS in the
  99. ENTRY DIFF3 violates section 15.7.4 of the Fortran standard.
  100.  
  101. The reason is this: Fortran does not pass around copies of arrays in
  102. function calls, it passes around an array reference.  Let's say I had the
  103. code sequence:
  104.  
  105.     PROGRAM FOO
  106.  
  107.     CALL A
  108.     CALL B
  109.     CALL DIFF3(...)
  110.     END
  111.  
  112.     SUBROUTINE A
  113.     DIMENSION F1(10)
  114.     CALL DIFF1(F1)
  115.     RETURN
  116.     END
  117.  
  118.     SUBROUTINE B
  119.     DIMENSION F2(10)
  120.     CALL DIFF2(F2)
  121.     RETURN
  122.     END
  123.  
  124. The arrays F1 and F2 in SUBROUTINES A & B would be locally allocated on the
  125. call stack during the execution of their respective routines.  In fact, it
  126. is highly likely that F1 and F2 would occupy the exact same address range on
  127. the stack in this case.  The extents or life times of these arrays is limited
  128. to the extent of time the SUBROUTINE is called.  As soon as the SUBROUTINE
  129. returns, any reference to F1 (or F2) is invalid.  Your DIFF3 function is
  130. trying to reference possibly invalid data.
  131.  
  132. The whole reason your program works when compiled -static is that the
  133. arrays F1 and F2 would be kept around in static storage instead of being
  134. automatically allocated on the stack during the invokation of A or B.
  135. Also, the dummy variables XS and XR now have static allocation and so
  136. their array references happen to keep around the addresses of the old
  137. values.
  138.  
  139. |> I detected this anomaly in a larger program.  In this, the use
  140. |> of three entry points to a subroutine is used to allow calculations
  141. |> to be done on pairs of arrays selected from a much larger number than two.
  142. |> Thus if there are n arrays the number of subroutine calls is 2*n rather than
  143. |> n**2 (which is the case if both selected arrays are to be passed as 
  144. |> parameters together in a single subroutine call.  
  145.  
  146. I'm sorry, I don't understand what you are trying to say here.
  147.  
  148. -- 
  149.  
  150.     __   * __   _  __  ___            
  151.    /  \ / / /  / \/  \/   \     He was a man like any other man, however, not
  152.   /    /  \/  /  /\  /    /    quite like any other man.
  153.   \___/\__/\_/  /_/ / \__/    
  154.                *        
  155.