Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28746 Discussions

ENTRY Statements in Function Subprograms

e745200
Beginner
388 Views
The documentation says :

"All entry names within a function subprogram are associated with the name of the function subprogram. Therefore, defining any entry name or the name of the function subprogram defines all the associated names with the same data type. All associated names with different data types become undefined."

Well, in the following code, the function subprogram and the entry have different types, and it compiles and runs smoothly. According to the documentation, I should have some troubles. I did not.
Is anyway advisable avoiding entries of different types ? Is it a violation of the standard ?
Thanks for your attention.


[fxfortran]       PROGRAM TFENTRY
       REAL(8)  :: A,B,C,D,E,F
       EXTERNAL :: MFUN, RFUN

       A=1.D0
       B=2.D0
       C=4.D0
       D=8.D0

       mmfun=mfun(a,b)
       rrfun=rfun(c,d)
       write (*,*) a,b,mmfun
       write (*,*) c,d,rrfun

       STOP
       END


       FUNCTION MFUN(P1,P2)
       REAL(8) :: P1,P2,P3,P4
       REAL(8) :: A,B

       A = P1
       B = P2
       MFUN = A+B
       write (*,*) 'in mfun ',P1,P2,mfun
       GOTO 10

       ENTRY RFUN(P3,P4)
       A = P3
       B = P4
       RFUN = A+B
       write (*,*) 'in rfun ',P3,P4,rfun

  10 CONTINUE
       RETURN

       END
[/fxfortran]


0 Kudos
2 Replies
Steven_L_Intel1
Employee
388 Views
This code is fine. What the standard says is that when you assign to MFUN, then any value previously assigned to RFUN is undefined, and vice-versa. Your example never uses the value of the "other" entry. For example, if you removed the GOTO in MFUN and, in the WRITE at line 33 you wrote out the value of mfun, it would be "wrong".
0 Kudos
e745200
Beginner
388 Views
Thanks a lot for your really prompt response.

Then, I had misunderstood the meaning of "defines" in the documentation.
I did not get it referred to the behavior at runtime, and not at "declaration" time.
Thanks again.



0 Kudos
Reply