문제

The following code gives segmentation error when compiled with pgf90 on the Linux system, while is run successfully when I used the Intel Visual FORTRAN on Windows.

program main 
implicit none 
integer:: a(3), b(3) ,c(3)
a=[3, 4, 5]
b=[1, 2, 3]
call sub(a,b,c)
write(*,*)'a+b = ',c 
end program main

subroutine sub(a,b,c) 
implicit none 
integer, intent(in)::a(:),b(:)
integer, intent(out)::c(:)
c=a+b
end subroutine sub 

Any explanation for this ?

도움이 되었습니까?

해결책

When you call a subroutine which has assumed shape dummy arguments (as is the case in this program), an explicit interface is required. The easiest way to achieve this, is to put the subroutine in a module, and use the module in the main program.

다른 팁

It might be helpful to use standard Fortran 90 syntax, specifically in how you declare and initialize arrays.

 program main 
 implicit none 
 integer, dimension(3):: a, b ,c
 a=(/3, 4, 5/)
 b=(/1, 2, 3 /)
 call sub(a,b,c)
 write(*,*)'a+b = ',c 
 end program main
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top