|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
AntonioGJerez
Joined: 01 Jun 2015 Posts: 9 Location: Spain
|
Posted: Sat Jun 20, 2015 2:35 pm Post subject: problems array valued functions |
|
|
Dear all
I have found several problems with array valued functions. They are probably my fault. Nevertheless I think the diagnosis of the compiler may be better.
This is the first example. It fails at runtime if compiled with /CHECKMATE depending on whether an unused variable N is passed to the function via USE or not
Code: | module global
integer::N=1
interface fun
function fun(A,B)
REAL,intent(in)::A(:),B(:)
REAL fun(size(A),size(B))
end function fun
end interface
end module
program bug6
use global,only:fun
REAL A(4),B(4,4)
A=(/1.,2.,3.,4./)
B=fun(A,A)
PRINT*,B
end program
function fun(A,B)
use global,only:N ! Crashes (integer overflow) due to this line if
!compiled with /CHECKMATE !!!!
implicit none
REAL,intent(in)::A(:),B(:)
REAL fun(size(A),size(B))
fun=5. ! the error message points to this line
end function fun |
Probably the reference at N should be included in the interface too.
In fact, this versión does not fail:
Code: | module Nmodule
integer::N=1
end module
module global
interface fun
function fun(A,B)
use Nmodule
REAL,intent(in)::A(:),B(:)
REAL fun(size(A),size(B))
end function fun
end interface
end module
program bug6fixed
use global,only:fun
REAL A(4),B(4,4)
A=(/1.,2.,3.,4./)
B=fun(A,A)
PRINT*,B
end program
function fun(A,B)
use Nmodule
implicit none
REAL,intent(in)::A(:),B(:)
REAL fun(size(A),size(B))
fun=5.
end function fun |
Regards |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Fri Jul 10, 2015 8:54 am Post subject: |
|
|
Is the following what you wanted ? Code: | module global
integer::N=1
contains
function fun(A,B)
implicit none
REAL,intent(in)::A(:),B(:)
REAL fun(size(A),size(B))
fun=5. ! the error message points to this line
end function fun
end module global
program bug6
use global,only:fun
REAL A(4),B(4,4)
A=(/1.,2.,3.,4./)
B=fun(A,A)
PRINT*,B
end program
|
I would get the program working, before applying ",only" to the use statement. Why the reference to N ? |
|
Back to top |
|
|
|
|
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
|