The following program gives me a bus error… any ideas why?
program main
integer, parameter :: n = 3
integer, dimension(n) :: out
out = rep(1,n)
print *, (out(i), i=1,n)
end program
function rep(x,n)
integer :: x
integer :: n
integer, dimension(n) :: rep
do i=1,n
rep(i) = x
enddo
end function
I think it has to do with the integer, dimension(n) :: rep but I’m not sure why this is happening.
You need to make the interface explicit to make sure that Fortran knows what rep is when you call it. put your rep function into a module in a separate file like this:
then use the module in your main program with the line
Also, use implicit none to make sure all your variables are declared properly.