(j3.2006) implicit typing

Robert Corbett robert.corbett
Tue Aug 23 00:12:57 EDT 2016


On 8/21/2016 10:14 AM, Bill Long wrote:
> On Aug 20, 2016, at 8:05 AM, Robert Corbett <robert.corbett at oracle.com> wrote:
>
>> Ian Harvey posted the following program to
>> comp.lang.fortran.
>>
>>     DIMENSION c(2)
>>     PARAMETER(i=SIZE(c))
>>     INTEGER c
>>     END
>>
>> He said none of the compilers he tried would compile
>> the program, but that he failed to find s rule in
>> the Fortran standard that it violated.  He pointed
>> out that the definition of a constant expression does
>> not include the restriction regarding agreement of
>> implicit and explicit types that is given for
>> specification expressions.
> I?m not sure why that is relevant.

When Oracle Developer Studio Fortran is used to compile the
code, the compiler does not detect an error on the PARAMETER
statement.  It detects an error on the type declaration
statement complaining that the type of the variable must be
REAL.  My guess is that that is how the other compilers
failed as well.

Bob Corbett

> The SIZE(c) reference does not depend on the type of C, only the shape, which was previously declared.  The question is wether the appearance of C as an argument to SIZE is sufficient to cause it to be implicitly typed as REAL,  which is then contradicted by the INTEGER declaration that comes later. As an experiment, try adding implicit none; integer i  at the beginning of the code.   If you still see an error about the type of C not being declared before C appears elsewhere, that is the issue.

The reported error is not that C is used before it is declared.
The reported erroris that the type given to C by the explicit
type declaration statement is not REAL.  Adding IMPLICIT NONE
causes the compiler to report an addition error because the
named constant i is not typed, but the message for the INTEGER
statement differs only in the line number.

Bob Corbett
> I have reduced sympathy for cases like this, since no respectable coding style guide would permit the use of either the DIMENSION or PARAMETER statements.





More information about the J3 mailing list