- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am new to the forum and I am using the non-commercial license, hope this is the right place to post my problem.
I have a derived type with an array component and a type bound function that returns a pointer to an element of that array. I get correct results if I just print the pointer, but as soon as I try to modify the array values using the pointer I get a catastrophic error.
A very simplified code that reproduces the error is:
[fortran]module mymodule
type :: vec
integer :: x(3)
contains
procedure :: at
end type vec
contains
function at( this, i ) result( p )
implicit none
class(vec), intent(in), target :: this
integer, intent(in) :: i
integer, pointer :: p
p => this%x(i)
end function at
end module mymodule
!---------------------------------------------
program test
use mymodule
implicit none
type(vec) :: myvec
myvec%x = [1,2,3]
! poiter returned by at gives the correct value
write(6,*) myvec%at(1), myvec%at(2), myvec%at(3)
! change any array element gives error
myvec%at(1) = 4
myvec%at(2) = 5
myvec%at(3) = 6
! check modified values
write(6,*) myvec%at(1), myvec%at(2), myvec%at(3)
end program test [/fortran]
Compiling I get:
ifort test.f90 -o test.r
test.f90(32): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error.
compilation aborted for test.f90 (code 1)
However if I modify the test program to use an additional pointer instead of the one returned by the at() function everything goes fine:
[fortran]program test
use mymodule
implicit none
type(vec) :: myvec
integer, pointer :: t1, t2, t3
myvec%x = [1,2,3]
! poiter returned by at gives the correct value
write(6,*) myvec%at(1), myvec%at(2), myvec%at(3)
! change array elements
t1 => myvec%at(1)
t2 => myvec%at(2)
t3 => myvec%at(3)
t1 = 4
t2 = 5
t3 = 6
! check modified values
write(6,*) myvec%at(1), myvec%at(2), myvec%at(3)
end program test[/fortran]
Compile line and output is:
ifort test.f90 -o test.r
test.r
1 2 3
4 5 6
which is correct. I am confused!
I hope someone can help me understanding where is the error. The ifort release I am using is:
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.0.1.117 Build 20121010
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
FOR NON-COMMERCIAL USE ONLY
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Internal Compiler Error is always a compiler bug. This forum is exactly the right place to report it - thanks!
You are trying to use a feature of Fortran 2008, assigning to a pointer function result, that is not yet implemented. The compiler ought to give a more meaningful error message for this.
I will escalate this to the developers for a fix. Please use the separate pointer as it may be some time before we implement pointer functions on the left side of an assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks for the quick reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The internal compiler error should be fixed in Update 4. Implementing this feature is still in the future.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page