Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Strange error message for code with undeclared variable

mecej4
Honored Contributor III
385 Views

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
andrew_4619
Honored Contributor II
385 Views

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

0 Kudos
jimdempseyatthecove
Honored Contributor III
385 Views

Steve,

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

0 Kudos
Steve_Lionel
Honored Contributor III
385 Views

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.

0 Kudos
Arjen_Markus
Honored Contributor I
385 Views

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

0 Kudos
Reply