Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

type declaration of function names and interfaces

8 views
Skip to first unread message

Giorgio Pastore

unread,
May 1, 2009, 1:42:05 PM5/1/09
to
I cannot find in the standard the exact points relevant to understand
which of the following different behaviors of Intel fortran compiler
(version 10.1 for Linux), gfortran (version 4.1.2) and g95 (version
0.92) is standard compliant:

- all ifort, gfortran and g95 compile programs which either have an
explicit interface or use a module containing a function *without* an
explicit type declaration of the function name in the program unit using
the function;

- if there is an explicit interface and the type declaration follows the
interface both g95 and gfortran compile without problems but ifort does not;

- if the type declaration precedes the explicit interface or if the
function is in a module gfortran compiles but g95 and ifort finds a
symbol conflict.

Does the standard resolve this conflicting behavior ? I have not been
able to find a clear statement about possible interference between
explicit, implicit interfaces and type declaration. And also on
precedence rules between type declaration and explicit interfaces.

Giorgio

P.S. Here I include a small testing code (enabling and disabling
comments one can experiment all the mentioned cases).

module fun
contains
function square(x) result (s)
real,intent(in) :: x
real :: s
s=x**2
end function square
end module fun


program aaa
use fun
implicit none

real :: square

!interface
! function square (x) result (s)
! real,intent (in) ::x
! real ::s
! end function square
!end interface

!real :: square

print*,square(10.0)

end program aaa


Tobias Burnus

unread,
May 1, 2009, 3:36:24 PM5/1/09
to
Giorgio Pastore wrote:
> I cannot find in the standard the exact points relevant to understand
> which of the following different behaviors of Intel fortran compiler
> (version 10.1 for Linux), gfortran (version 4.1.2) and g95 (version
> 0.92) is standard compliant:

You should compile with the option -std=f95 (or -std=f2003) for g95 and
gfortran and the option -stand f95 (or -stand f03) for ifort - the
default settings might allow certain things which are not allowed by the
standard.


> - all ifort, gfortran and g95 compile programs which either have an
> explicit interface or use a module containing a function *without* an
> explicit type declaration of the function name in the program unit using
> the function;

That is valid according to the standard.


> - if there is an explicit interface and the type declaration follows the
> interface both g95 and gfortran compile without problems but ifort does
> not;

The code is invalid (see below). For gfortran I filled a bug.

> - if the type declaration precedes the explicit interface or if the
> function is in a module gfortran compiles but g95 and ifort finds a
> symbol conflict.

Try -std=f95 or use GCC/gfortran 4.4.x/4.5.

> Does the standard resolve this conflicting behavior ? I have not been
> able to find a clear statement about possible interference between
> explicit, implicit interfaces and type declaration. And also on
> precedence rules between type declaration and explicit interfaces.

See Fortran 2003 standard:

"C508 An entity shall not be explicitly given any attribute more than
once in a scoping unit."

An exception is that implicitly typed entity might get their type
confirmed by an explicit typing. Or in the more precise words of the
standard (5.1.1 Declaration type specifiers):

"The declaration-type-spec in a type declaration statement specifies the
type of the entities in the entity declaration list. This explicit type
declaration may override or confirm the implicit type that could
otherwise be indicated by the first letter of an entity name (5.3)."

Tobias

Giorgio Pastore

unread,
May 1, 2009, 6:19:16 PM5/1/09
to
Tobias Burnus wrote:
...

> See Fortran 2003 standard:
>
> "C508 An entity shall not be explicitly given any attribute more than
> once in a scoping unit."

Your reply clarified a lot of things. I find a little disappointing
that could not find clearly stated (both in the standard and in the
few books on Fortran I have consulted) that the explicit interface
block it is not only there to provide information to the compiler to
perform consistency checks or to allow specific subprogram features but,
when it appears, it is the only type definition for the function name.
If I understood correctly.

Giorgio

0 new messages