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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 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.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.