-warn interface and derived types

-warn interface and derived types

RHEL 5.4, 64-bit. Compiler version 12.0.3.

I have a derived type, which is used to pass an argument from a program to a subroutine.

Here is the definition of the derived type, which resides in x.crd

type x_t
integer*4 i
end type

The subroutine, in s.for, is:
subroutine s(x)
implicit none
include 'x.crd'
type(x_t)::x
type *, x
end

And the main program, in m.for, is

program m
implicit none
include 'x.crd'
type(x_t)::x
call s(x)
end

I have IFORTCFG set to nothing. I run these commands, and get the error shown:

$ ifort -c -warn interface s.for
$ifort -c -warn interface m.for
m.for(5): error #6633: The type of the actual argument differs from the type of the dummy argument. [X]
call s(x)
---------------^
compilation aborted for m.for (code 1)

Here is the generated interface block, from s__genmod.f90

!COMPILER-GENERATED INTERFACE MODULE: Tue May 10 14:25:57 2011
MODULE S__genmod
INTERFACE
SUBROUTINE S(X)
TYPE X_T
INTEGER(KIND=4) :: I
END TYPE X_T
TYPE (X_T) :: X
END SUBROUTINE S
END INTERFACE
END MODULE S__genmod

What is the compiler complaining about?

Thanks

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Steve Lionel (Intel)'s picture

You have two different X_T types that have the same components, but they are not the same type in Fortran's eyes. Yes, this will work if you don't have generated interface checking, even though it is technically non-standard, but with an explicit interface, generated or actual, there's no way to represent this. The Fortran language would have you put X_T in a module and USE that.

Steve
mecej4's picture

At first encounter this message is perplexing, but it follows from the way that the Fortran Standard specifies type compatibility.

Section 5.1.1.1 of the standard says:

8 Where a data entity is declared explicitly using the TYPE type specifier, the specified derived type shall
9 have been defined previously in the scoping unit or be accessible there by use or host association.

That may seem to shed little light on the issue, so consider this reinterpretation in Metcalf, Reid and Cohen's book, 'Fortran 95/2003 Explained':

Different declarations of a TYPE, even if the declarations are
identical, do not create argument-compatible types (with few
exceptions). That is why it is necessary to create a single definition,
in a module if necessary, and USE that definition wherever it is
needed.

Steve Lionel (Intel)'s picture

Exactly. BTW, Metcalf/Reid/Cohen have a new edition of their book out that covers Fortran 2008. They ran out of room for numbers so they just call it "Modern Fortran Explained" now. I got a copy yesterday.

Steve
mecej4's picture

I received my copy in 2006 as a reward for answering an Intel online survey on Fortran. With its reasonable size and concise explanations, for me it lowered the barrier to making the transition from F77 to F95.

Login to leave a comment.