From: calvin@dinkum.wpd.sgi.com (Calvin H. Vu)
Newsgroups: comp.sys.sgi
Subject: Re: Fortran problem on going from 4.0.1 to 4.0.5
Date: 1 Sep 92 16:09:45 GMT
Organization: Silicon Graphics, Inc.  Mountain View, CA

In <1992Aug31.161432.1@vaxa.strath.ac.uk> cbas25@vaxa.strath.ac.uk writes:

| The following fortran program illustrates a problem which has arisen on
| going from IRIX 4.0.1 to IRIX 4.0.5.
	I don't think it will work in any releases without the -static
    flag.
| 
| C-------------------------------cut here-------------------------
|       PROGRAM TESTPRO
|       COMMON/A/XA(10)
|       COMMON/B/XB(10)
|       DO 100 I = 1,10
|            XA(I) = FLOAT(I)
|            XB(I) = 10.0 - FLOAT(I)
| 100   CONTINUE
| 
|       WRITE (*,1000)
| 1000  FORMAT ('Enter to numbers between 1 and 10 inclusive')
|       READ  (*,*) K,L
| 
|       CALL DIFF1 (XA)
|       CALL DIFF2 (XB)
|       CALL DIFF3 (K,L,RESULT)
|       WRITE (*,*) RESULT
| 
|       CALL ONCE (XA,XB,K,L,RESULT)
|       WRITE (*,*) RESULT
| 
|       STOP
|       END
| 
|       SUBROUTINE ONCE (XR,XS,I,J,D)
|       DIMENSION XR(10)
|       DIMENSION XS(10)
|       write (*,*) i,j,xr(i),xs(j)
|       D = XR(I) - XS(J)
|       RETURN
|       END
| 
|       SUBROUTINE DIFFER
|       SAVE
|       DIMENSION XR(10)
|       DIMENSION XS(10)
|       ENTRY DIFF1 (XR)
|       RETURN
|       ENTRY DIFF2 (XS)
|       RETURN
|       ENTRY DIFF3 (I,J,D)
|       write (*,*) i,j,xr(i),xs(j)  !Program fails here when '-static' not used
|       D = XR(I) - XS(J)
|       RETURN
|       END 

	Everything Dave Ciemewics said regarding the Fortran standard
applies.  However, the reason your program works with -static is because
that flag (which is almost a must for any programs written for the VMS
environment and use its extensions liberally) is because the -static flag
also triggers a VMS extension which saves the dummy arguments in a 
multiple-entry subroutine in a static location.  Therefore, with the
-static flag your program will have these system-dependent non-ANSI 
side effects:

       CALL DIFF1 (XA)	! save the address of XA in a static location
			! reserved for the dummy argument XR
			! of the multiple-entry subroutine DIFFER
       CALL DIFF2 (XB)	! save the address of XB in a static location
			! reserved for the dummy argument XS
			! of the multiple-entry subroutine DIFFER
       CALL DIFF3 (K,L,RESULT)	! calling DIFF3 assuming that the dummy
				! arguments XR and XS have been saved
				! by the previous two calls to contain the
				! addresses of XA and XB

	If we just look at this simple example then it could be much
improved by adding two more dummy argument XR and XS to the argument list
of DIFF3 (and call it with the proper actual arguments of course).  In that
way, you only need one call to DIFF3 instead of three (to DIFF1, DIFF2, and
DIFF3) and it is also portable across all platforms.

	I guess this side effect of the -static flag could have been 
implemented as a separate option, e.g. -vms_entry, to avoid the confusion
why it works with -static and not with SAVE statement.  But, since it has
already done that way I'll make a point to document this side-effect
in the man f77 page so it won't cause this confusion.

| Has anyone had similar problems.
| 
| Peter Bladon
| University of Strathclyde
| Department of Pure and Applied Chemistry
| Glasgow G1 1XL      
| 
| e-mail  cbas25%vaxa.strath.ac.uk

Hope it helps,

- calvin
--
-----------------------------------------------------------------------------
Calvin H. Vu			   | "We are each of us angels with only one
Silicon Graphics Computer Systems  | wing.  And we can only fly embracing
calvin@sgi.com   (415) 962-3679	   | each other."