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

FINAL Procedure

holysword
Novice
701 Views
Hi everybody,
I've read in Intel's website that the FINAL procedure is already supported (some kind of destructor). I've got a book with some examples of usage of such feature, but none of them work with Intel's compiler. The following example
[fortran]MODULE my_class

 IMPLICIT NONE

 PRIVATE
 
TYPE :: c_my_class
	INTEGER :: test
	CONTAINS
		FINAL :: destroy
END TYPE c_my_class


CONTAINS 
SUBROUTINE destroy(self)
	TYPE(c_my_class) :: self
	
	PRINT *, 'This is destroy'
END SUBROUTINE destroy

END MODULE my_class[/fortran]
won't compile, returning

error #5082: Syntax error, found '::' when expecting one of: ( % : . = =>
FINAL :: destroy
----------------------^
Any ideas? I am usingifort 11.1 20100414
Thanks in advance!
0 Kudos
1 Solution
Steven_L_Intel1
Employee
701 Views
11.1 is an old version. Current is 12.0 and the first to support FINAL. The product name is Intel Fortran Composer XE 2011.

I turned your code into a complete program to show it working. (Needed to add the PUBLIC declaration to make the type visible. Pardon my Windows.
[plain]E:Projects>type f.f90
MODULE my_class

 IMPLICIT NONE
 PRIVATE
 PUBLIC :: c_my_class

TYPE :: c_my_class
        INTEGER :: test
        CONTAINS
                FINAL :: destroy
END TYPE c_my_class


CONTAINS
SUBROUTINE destroy(self)
        TYPE(c_my_class) :: self

        PRINT *, 'This is destroy'
END SUBROUTINE destroy

END MODULE my_class

program test
use my_class
call sub

contains
subroutine sub
type(c_my_class) :: x
end subroutine sub
end program test
E:Projects>ifort f.f90
Intel Visual Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:f.exe
-subsystem:console
f.obj

E:Projects>f.exe
 This is destroy

E:Projects>[/plain]
An important note - FINAL procedures do NOT get called when a program reaches its END statement, hence the subroutine.

View solution in original post

0 Kudos
3 Replies
TimP
Honored Contributor III
701 Views
FINAL should be supported in current compilers (looks like a clean compile), but not in one which was issued over a year ago.
0 Kudos
Steven_L_Intel1
Employee
702 Views
11.1 is an old version. Current is 12.0 and the first to support FINAL. The product name is Intel Fortran Composer XE 2011.

I turned your code into a complete program to show it working. (Needed to add the PUBLIC declaration to make the type visible. Pardon my Windows.
[plain]E:Projects>type f.f90
MODULE my_class

 IMPLICIT NONE
 PRIVATE
 PUBLIC :: c_my_class

TYPE :: c_my_class
        INTEGER :: test
        CONTAINS
                FINAL :: destroy
END TYPE c_my_class


CONTAINS
SUBROUTINE destroy(self)
        TYPE(c_my_class) :: self

        PRINT *, 'This is destroy'
END SUBROUTINE destroy

END MODULE my_class

program test
use my_class
call sub

contains
subroutine sub
type(c_my_class) :: x
end subroutine sub
end program test
E:Projects>ifort f.f90
Intel Visual Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:f.exe
-subsystem:console
f.obj

E:Projects>f.exe
 This is destroy

E:Projects>[/plain]
An important note - FINAL procedures do NOT get called when a program reaches its END statement, hence the subroutine.
0 Kudos
holysword
Novice
701 Views
Yes, I was misled by my system's package manager, which claims that my ifc is up to date.
I will install it manually. Thank you very much.
0 Kudos
Reply