- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all.
Trying to learn how to do OOP with Fortran, and receiving " error #8339: The dummy argument of a final subroutine must be a variable of the derived type being defined and cannot be optional, pointer, allocatable, or polymorphic. [THIS] " when trying to run a modified example of S.C.Chapman "Fortran 95/2003 for Scientists and Engineers" (3rd edition), about how to use finalizers (in page 790). I was trying to change the real vector class in that example by a character string class (same error with the real vector in the book), to add some methods afterwards, and to see if I was able to emulate the behavior of string classes in other languages. The book warns the code in the example might not work in the Fortran compilers available by that time. Code is attached. I am using Intel Compiler XE v14 SP1.
Any advice?
Thanks and regards.
module class_string implicit none type, public :: string character, dimension(:), pointer :: text logical :: is_allocated = .false. contains final :: clean_text end type contains subroutine clean_text(this) class(string) :: this integer :: istat if (this%is_allocated) then deallocate(this%text, stat=istat) end if end subroutine end module
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The message says that the dummy argument can not be (among others) polymorphic. Hence you cannot use the "class" keyword. You will have to use "type" instead and define a specific final subroutine for descendant classes, if the need arises. I have hardly used them myself so far. In this particular case you could do without it - replace the pointer to a character string by an allocatable and the deallocation now required will be automatic.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The example in the book is wrong, which astonishes me somewhat because I know Chapman used the Intel compiler on the examples. I checked the original sample from the book and it gets the same error. This is not mentioned in the errata, though I see the errata has not been updated since 2007.
Curiously, the ZIP for the book's examples includes an alternate version of this sample with the argument to the FINAL routine declared with TYPE rather than CLASS, but the FINAL declaration itself is commented out. I will write Chapman about this and see what he says.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The program violates F2003 constraint C473 (C480 in F2008) which says, “That argument shall be nonoptional and shall be a nonpointer, nonallocatable, nonpolymorphic variable of the derived type being defined.”
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Arjen and Steve. Thanks to both for the quick answer. Changing the code with class by type and pointer by allocatable makes it work. Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You may also want to review the books mentioned in Dr Fortran blog: https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world which are more up-to-date with OOP features than the Chapman book. In particular, take a look at the book in the footnote by Rouson et al. on Scientific Software Design: The Object-Oriented Way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. If I manage to get copies of the books in that page I'll review them. I understand, if mentioned herein, that the last one also deals with fortran specificities. Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Chapman responded to me:
As it happens, the code examples shown were done before IVF implemented of the features, and I did them based on reading the standard! By good fortune, I am starting a revision of the book this Autumn, and I will incorporate the fix then.

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