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:
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
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:
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
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!


