Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26732 Discussions

Strange error message for code with undeclared variable

Black Belt

The code below is missing a declaration "INTEGER :: I".

subroutine bsub
implicit none
integer :: ia(2) = [(i+2, i=2,3)]

print *,(i,ia(i),i=1,2)
end subroutine

Therefore, error messages and aborting of the compilation are expected. The 18.0.5 and 19.0.1 compilers say:

bsub.f90(3): error #6404: This name does not have a type, and must have an explicit type.   
integer :: ia(2) = [(i+2, i=2,3)]
bsub.f90(5): error #6404: This name does not have a type, and must have an explicit type.   
print *,(i,ia(i),i=1,2)
bsub.f90(5): error #6063: An INTEGER or REAL data type is required in this context.   
print *,(i,ia(i),i=1,2)
bsub.f90(5): error #8251: An input item must not appear as the implied-DO variable of any implied-DO loop that contains the input item.   
print *,(i,ia(i),i=1,2)
compilation aborted for bsub.f90 (code 1)

The last error message would have been appropriate if the code had contained a READ statement with the same implied DO list as the PRINT statement.

0 Kudos
4 Replies
Honored Contributor I

I guess it is not that unusual though for an first  error message to lead a cascade of consequential and often spurious messages.  

Black Belt


Does the Fortran standard require the indexing variable of an implied DO loop to the declared (at all, much less than explicitly as integer)?

Jim Dempsey

Black Belt Retired Employee

If IMPLICIT NONE is in effect, yes it does, the same as any other variable. Here is what the standard says for the implied DO in an array constructor:

The name of a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor has a scope of its data-implied-do or ac-implied-do. It is a scalar variable. If integer-type-spec appears in data-implied-do or ac-implied-do-control it has the specified type and type parameters; otherwise it has the type and type parameters that it would have if it were the name of a variable in the innermost executable construct or scoping unit that includes the DATA statement or array constructor, and this type shall be integer type. It has no other attributes. The appearance of a name as a data-i-do-variable of an implied DO in a DATA statement or an ac-do-variable in an array constructor is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement.

The implied DO in the I/O statement is different in that it IS a variable in the enclosing scope, but you are still required to declare it if it wouldn't otherwise have an implicit integer type.

Valued Contributor III

See also the recent discussion by mecej4 on comp.lang.fortran :).