3

I am trying to understand the Fortran code contained in: http://heath.cs.illinois.edu/courses/cs598mh/george_liu.pdf

Specifically, array variable declarations in subroutines. Here is an example:

      SUBROUTINE ROOTLS (ROOT, XADJ, ADJNCY, MASK, NLVL, XLS, LS)
C
         INTEGER ADJNCY(1), LS(1), MASK(1), XLS(1)
         INTEGER XADJ(1), I, J, JSTOP, JSTRT, LBEGIN

I am confused by the (1) after the name of the array for example ADJNCY(1) and XADJ(1). These arrays are definitely larger than one. What does the (1) do in these declarations?

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
Khubunku
  • 79
  • 1
  • 3

1 Answers1

3

In fact, this is not FORTRAN 77, but FORTRAN 66 ;-)

The (1) is a dirty hack in FORTRAN 66 to construct something like an assumed-size array. In FORTRAN 77 this was standardized to (*).

Assumed-size means that the actual of the array depends on the length of the actual array passed to the subroutine. Note, though, that the shape of the array is not necessarily preserved! Se here for an excellent explanation on this.

Community
  • 1
  • 1
Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
  • just because someone used an old convention doesn't mean the code is that old. I'm surprised by the claim in that link that says modern compilers forbid this. intel accepts it. Obviously you shouldn't continue to use this for new code, but there is no reason to go modifying old library code to fix it. – agentp May 26 '15 at 19:51
  • 1
    @agentp The compiler accepts it, *if it does not check the arguments* (e.g with external libraries)! As soon as you provide an interface to the function/subroutine (e.g. usage in a module), the compiler will most certainly not accept it. – Alexander Vogt May 26 '15 at 20:19
  • @agentp as soon as the subroutine starts to access anythinh after the first element the code is not standard conforming. I would be very surprised if the bounds checking did not catch it if it is enabled. I am not aware of any exception in the standard allowing this. – Vladimir F Героям слава May 27 '15 at 06:54
  • fwiw ifort accepts it even with bounds checking enabled. `(1)` appears to be specially treated as defining an assumed size array the same as `(*)`, while anything else, `(2)` for example, is treated as an actual dimension. – agentp May 27 '15 at 14:22