Search code examples
parametersfortranbus-error

Fortran Bus Error When Modifying Parameter


Whenever I assign a new value to a parameter, I get a bus error. I don't see how I'm pointing to non-existant memory. I should have access to this address, as it is declared in the parameter list, unless Fortran does not allow parameters to be modified without some special declaration. The rest of my code works without error. I've isolated it to simply this assignment.

I'm running gfortran (not sure which version, off-hand) from the terminal in OS X.

SUBROUTINE p_list (c_number, c_matrix)
    INTEGER     c_number
    INTEGER     c_matrix(8000,20)
!   ... 
    c_number = 1000
!   ...
END SUBROUTINE p_list

Solution

  • How are you calling this? I don't know modern FORTRANs, but I know that with earlier versions of FORTRAN, you could crash a program like that by passing in a constant (e.g., by calling p_list(0, my_matrix)). That's because FORTRAN implicitly passed everything by reference, including constants (!)