Compiler option to warn about argument declarations of x(1) instead of x(*)

In its old versions, C allowed c[i] and i[c] to represent the same element of the array c. I am thankful that Fortran did not allow such confusing usage.

#include <stdio.h>

int main()
{
    int i,c[4];
    for(i=0; i<4;i++)c[i] = 3*i+2;
    i=3; printf("%3d %5d %5d\n",i,i[c],c[i]);

    return 0;
}

Although it might look like this superficially, I don’t think that is the best way to describe the assumed size feature. x(*) is a rank 1 dummy array, regardless of the rank of its actual argument. This worked because of storage sequence association, not because the * could represent arbitrary ranks. There are also dummy argument declarations like x(m,*), x(m,n,*) and so on that actually do correspond to higher-rank assumed size arrays with unspecified size in the last dimension. All of this worked because the last dimension is not used in the storage sequence association index expressions. For example, in the rank-2 case, the index of x(i,j) is given as (i-1)*m+j, where m is necessary in the expression, but the size of the last dimension isn’t. In f77, and earlier, all arrays were contiguous, so these index expressions always worked with just the base address of the array and the dummy dimension declaration, no other information was needed in the argument association step. In modern fortran, dummy arrays are not necessarily contiguous, so extra information must be passed when assumed shape declarations for the dummy argument x(:,:) are used, and copy-in/copy-out argument association must be used when the dummy x(*) is associated with a noncontiguous actual argument. That is also why assumed shape dummy arguments, x(:), x(:,:), etc., require an explicit interface, but assumed size dummy arguments, x(*), x(m,*), etc., do not.

4 Likes