In article <
7c65958f-b788-499f...@googlegroups.com>,
deltaquattro <
deltaq...@gmail.com> wrote:
> Hi,
>
> I'm happily (?) working on legacy code: should be f77, but since the compiler
> is also legacy, I'm not exactly sure about that. I stumbled upon this:
>
> .
> .
> .
> INTEGER arSize
>
> PARAMETER (arSize = 10)
>
> INTEGER aryFOO
> INTEGER aryBAR
> INTEGER aryGOOFY
>
> COMMON /CKFIND/ aryFOO(arSize),
> . aryBAR(arSize),
> . aryGOOFY(arSize)
>
> Is this code standard conforming? I've never seen arrays declared this way.
Yes, not only is this standard conforming, but it is probably one of
the most common programming styles for arrays in common blocks. The
main issue with common blocks is alignment between different program
units. Because they must be specified in each separate compilation
unit, the most common mistake is to have inconsistent lengths, or
the wrong order, or any of dozens of other unintentional mistakes
related to alignment. The above style allows a programmer to see
immediately that the arrays are all of the same length.
> I'm used to either:
>
> INTEGER aryFOO(arSize) ! f77 style
> INTEGER aryBAR(arSize) !
> INTEGER aryGOOFY(arSize) !
That's fine too, but then the common declaration looks like you have
three scalars rather than three arrays. The programmer needs to
look around for the other parts of the declarations to see that they
are arrays and that they are the same size.
Both are alright, it is just a matter of style.
> or
>
> INTEGER, DIMENSION(arSize) :: aryFOO, aryBAR, aryGOOFY ! f90 style
That is new to f90, it was not allowed in f77. Again, it is a
matter of style, but something like
INTEGER :: aryFOO(arSize), aryBAR(arSize), aryGOOFY(arSize)
is probably more common. I personally never use DIMENSION
statements or the DIMENSION attribute.
> Declaring first an INTEGER scalar, and then a COMMON block where the scalar
> is redefined as an array, seems counterintuive (to say the least).
There are several things that are important, the array size (which
is defined by the parameter value), the type (INTEGER in these
cases), and the fact that they are in a common block which brings
the alignment issues to the front. F77 prevents you from specifying
all those things together, it requires that they be done on separate
lines. So you get to pick your poison.
> BTW, of
> course the PARAMETER statement is indispensable for the code to work, right?
The arrays in a common block must be declared with constants, not
variables. So expressions with either parameters or literal
constants are required.
Notice also that it is not possible to declare the type and value of
the parameter on a single line. F77 required two lines for that
too. If the two lines are next to each other, as in your example,
that's not so bad, but sometimes extra lines would be inserted in
between, and then the programmer had to waste some more time
tracking down what was going on, particularly, as in this case, when
the variable name was not consistent with the implicit typing rules.
This is another problem that f90 (and later) fixed.
$.02 -Ron Shepard