replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Pointer arguments
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer arguments

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Fri Jun 05, 2009 5:17 pm    Post subject: Pointer arguments Reply with quote

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
View user's profile Send private message
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Fri Jun 05, 2009 9:45 pm    Post subject: Reply with quote

... I should have mentioned that the program crashes only when compiled with /CHECK.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Sat Jun 06, 2009 4:05 am    Post subject: Reply with quote

Simon,
I can't see where "x" is defined or dimensioned.
John
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat Jun 06, 2009 2:08 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 299

PostPosted: Sat Jun 06, 2009 8:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sun Jun 07, 2009 8:12 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Jun 15, 2009 10:29 am    Post subject: Reply with quote

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group