View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 299
|
Posted: Fri Jun 05, 2009 5:17 pm Post subject: Pointer arguments |
|
|
The following program generates a run-time error at line 20, which simply assigns the value 0 to the argument i in subroutine s2. It seems to work on other compilers.
Code: | MODULE m
IMPLICIT NONE
TYPE t1
REAL :: r
END TYPE t1
TYPE(t1), POINTER, PUBLIC :: x(:)
CONTAINS
!
SUBROUTINE s1 (a,i)
INTEGER :: i
TYPE(t1), POINTER :: a(:)
i=0
CALL s2 (a,i)
RETURN
END SUBROUTINE s1
!
SUBROUTINE s2 (a,i)
INTEGER :: i
TYPE(t1), POINTER :: a(:)
i=0
RETURN
END SUBROUTINE s2
END MODULE m
PROGRAM p
USE m
IMPLICIT NONE
INTEGER :: i
!
CALL s1 (x,i)
END PROGRAM p
|
|
|
Back to top |
|
 |
simon
Joined: 05 Jul 2006 Posts: 299
|
Posted: Fri Jun 05, 2009 9:45 pm Post subject: |
|
|
... I should have mentioned that the program crashes only when compiled with /CHECK. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Sat Jun 06, 2009 4:05 am Post subject: |
|
|
Simon,
I can't see where "x" is defined or dimensioned.
John |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sat Jun 06, 2009 2:08 pm Post subject: |
|
|
You have discovered a bug in the compiler.
Basically you have pushed the argument checking process to its limits and the address of i has got corrupted on returning from S2.
However, you do not need to pass x in the calls to S1 and S2 because x is declared in the same module as S1 and S2 and so will be in scope anyway. If you avoid passing x as an argument then the problem goes away. |
|
Back to top |
|
 |
simon
Joined: 05 Jul 2006 Posts: 299
|
Posted: Sat Jun 06, 2009 8:21 pm Post subject: |
|
|
Good idea, but what if I want to call the same routine with two different arrays?
Code: | MODULE m
IMPLICIT NONE
TYPE t1
REAL :: r
END TYPE t1
TYPE(t1), POINTER, PUBLIC :: x(:)
TYPE(t1), POINTER, PUBLIC :: y(:)
CONTAINS
!
SUBROUTINE s1 (a,i)
INTEGER :: i
TYPE(t1), POINTER :: a(:)
i=0
CALL s2 (a,i)
RETURN
END SUBROUTINE s1
!
SUBROUTINE s2 (a,i)
INTEGER :: i
TYPE(t1), POINTER :: a(:)
i=0
RETURN
END SUBROUTINE s2
END MODULE m
PROGRAM p
USE m
IMPLICIT NONE
INTEGER :: i
!
CALL s1 (x,i)
CALL s1 (y,i)
END PROGRAM p |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sun Jun 07, 2009 8:12 am Post subject: |
|
|
For the moment you will need to find a different way to code this or avoid using /check etc. Hopefully the bug will be fixed for the next release.
It will probably work if you reverse the arguments because it is the first that is corrupting the second. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Jun 15, 2009 10:29 am Post subject: |
|
|
This bug has now been fixed for the next release. |
|
Back to top |
|
 |
|