- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Today I found some old code with pointers to subroutines. It looks like this:
[fxfortran] PROGRAM TESTThis code runs fine but it compiles only without /warn:interfaces. My attempts to correct the declarations result in internal compiler errors. Does someone know how to correct the declarations?
INTEGER LOCEX
EXTERNAL DEFEX
EXTERNAL TESTEX
C Save Pointer to external subroutine
CALL EXTERNALCALL('SAVE',LOC(TESTEX))
C Get Pointer to external subroutine
CALL EXTERNALCALL('GET',LOCEX)
C If not associated take DEFEX
IF(LOCEX.EQ.0) LOCEX=LOC(DEFEX)
C CALL LOCEX IN EXTERALTOOL
CALL CALLEXTERNAL(%VAL(LOCEX))
END
SUBROUTINE CALLEXTERNAL(EXPROG)
C Call an external subroutine
EXTERNAL EXPROG
CALL EXPROG
END
SUBROUTINE EXTERNALCALL(OPT,LOCEX)
C Save pointer to an external subroutine or return pointer to subroutine
CHARACTER(*) OPT
INTEGER LOCEX
INTEGER LOCEXSAVE
SAVE LOCEXSAVE
DATA LOCEXSAVE /0/
IF(OPT.EQ.'GET') THEN
LOCEX=LOCEXSAVE
ELSEIF(OPT.EQ.'SAVE') THEN
LOCEXSAVE=LOCEX
ENDIF
END
SUBROUTINE DEFEX
WRITE(*,*) "DEFEX"
READ(*,*)
END
SUBROUTINE TESTEX
WRITE(*,*) "TESTEX"
READ(*,*)
END[/fxfortran]
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you have done with the nonstandard extension functions %LOC and %VAL can be achieved with the procedure pointer feature of Fortran 2003. This feature is (newly) available in Intel Fortran, but many other compilers do not provide it yet.
Here is a simple example:
Here is a simple example:
[fortran]PROGRAM PROC_PTR_EXAMPLE REAL :: R1 INTEGER :: I1 INTERFACE SUBROUTINE SUB(X) REAL, INTENT(IN) :: X END SUBROUTINE SUB END INTERFACE PROCEDURE(SUB), POINTER :: PTR_TO_SUB => NULL() ! with explicit interface PROCEDURE(SUB), POINTER :: PTR_TO_SUB1 => NULL() ! with explicit interface EXTERNAL :: SUB1, SUB2 PTR_TO_SUB => SUB1 CALL PTR_TO_SUB(1.0) PTR_TO_SUB1 => SUB2 ! save pointer NULLIFY(PTR_TO_SUB) ! make PTR_TO_SUB not callable !... !... PTR_TO_SUB => PTR_TO_SUB1 ! restore pointer CALL PTR_TO_SUB(2.0) END PROGRAM PROC_PTR_EXAMPLE subroutine SUB1(X) real, intent(in) :: X write(*,10)x return 10 format(' SUB1 ',1pE15.5) end subroutine SUB1 subroutine SUB2(X) real, intent(in) :: X write(*,10)x*5 return 10 format(' SUB2 ',1pE15.5) end subroutine SUB2 [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even though I would prefer a solution for FORTRAN90/95 I also tried it with procedure pointes but all my attempts result in internal compiler errors.
Your solution also gives me an internal compiler error. When I remove line 13 and 16 (PTR_TO_SUB=>SUB1 and PTR_TO_SUB=>PTR_TO_SUB1) the error is gone.
I'm using Intel Visual Fortran 11.1.065 [IA-32]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't see an error with 11.1.065. Which compiler options are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here are my compiler options:
/nologo /debug:full /Od /gen-interfaces /debug-parameters:all /warn:declarations /warn:unused /warn:ignore_loc /warn:uncalled /warn:interfaces /iface:cvf /module:"c:/sw/wg/testprj_fortran" /object:"Debug\" /traceback /check:bounds /libs:static /threads /dbglibs /c
/nologo /debug:full /Od /gen-interfaces /debug-parameters:all /warn:declarations /warn:unused /warn:ignore_loc /warn:uncalled /warn:interfaces /iface:cvf /module:"c:/sw/wg/testprj_fortran" /object:"Debug\" /traceback /check:bounds /libs:static /threads /dbglibs /c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok - remove /iface:cvf and it works. Reported as issue DPD200158540.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm glad to hear that it was not again my stupidity. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has been fixed in our sources. I'm not exactly sure of the timing - the fix might be in Update 2 (out in a couple of weeks) but if not, Update 3.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page