- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have reproduced an error I am facing in a code with the following three files. The idea is that an abstract class contains a procedure pointer that I want to assign in the derived type. In the derived type the passed argument is changed to the derived type using the CLASS keyword. The program compiles and executes perfectly with gfortran 4.6.3. With ifort 12.1.5 there is the following error when compiling the derived type module with ifort -c derived.F90 (of course, this is after compiling the abstract module with ifort -c abstract.F90):
derived.F90(17): error #8178: The procedure pointer and the procedure target must have matching arguments.
THIS%procPtr => derived_sub
----^
compilation aborted for derived.F90 (code 1)
The code is contained in the following three files:
abstract.F90
[fortran]
MODULE abstract_m
TYPE,ABSTRACT,PUBLIC :: abstract_t
! The procedure pointer facing the problems.
PROCEDURE(abstract_proc),POINTER :: procPtr
CONTAINS
PROCEDURE(initX),PUBLIC,DEFERRED :: init
END TYPE abstract_t
ABSTRACT INTERFACE
SUBROUTINE abstract_proc(THIS)
IMPORT
CLASS(abstract_t),INTENT(IN) :: THIS
END SUBROUTINE abstract_proc
SUBROUTINE initX(THIS)
IMPORT
CLASS(abstract_t),INTENT(INOUT) :: THIS
END SUBROUTINE initX
END INTERFACE
END MODULE abstract_m
[/fortran]
derived.F90
[fortran]
MODULE derived_m
USE abstract_m
TYPE,PUBLIC,EXTENDS(abstract_t) :: derived_t
CONTAINS
PROCEDURE,PUBLIC :: init => init_sub
END TYPE derived_t
PRIVATE :: init_sub, derived_sub
CONTAINS
SUBROUTINE init_sub(THIS)
CLASS(derived_t),INTENT(INOUT) :: THIS
WRITE (*,*) 'Hello world from the derived object.'
THIS%procPtr => derived_sub
END SUBROUTINE init_sub
SUBROUTINE derived_sub(THIS)
CLASS(derived_t),INTENT(IN) :: THIS
WRITE (*,*) 'Hello world from the procedure pointer.'
END SUBROUTINE derived_sub
END MODULE derived_m
[/fortran]
main.F90
[fortran]
PROGRAM main
USE abstract_m
USE derived_m
IMPLICIT NONE
CLASS(abstract_t),POINTER :: objPtr
ALLOCATE(derived_t::objPtr)
CALL objPtr%init()
CALL objPtr%procPtr()
END PROGRAM main
[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:It has to be the way you describe, otherwise you'd be able to dynamically (run time) bind a procedure to an object where the passed argument was of the wrong type and the compiler would have to diagnose that (C456 in F2008) at compile time. (Imagine a different extension Xxx of abstract_t, create an object of it, pointer assign derived_sub to procPtr, call the pointer component - object of type Xxx being passed to a procedure that wants object of type derived_t).
I know this is not what you want to hear, but unless someone can come up with a convincing argument (with references to the standard) why I'm wrong, I'd say this is a bug in gfortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page