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

Generic Interface: Which is right?

13 views
Skip to first unread message

Athanasios Migdalas

unread,
Nov 14, 2010, 7:09:52 PM11/14/10
to
MODULE something
INTERFACE new_name
MODULE PROCEDURE func_name, subr_name
END INTERFACE
CONTAINS
LOGICAL FUNCTION func_name(arg1,arg2)
:
END FUNCTION

SUBROUTINE subr_name(arg1,arg2,arg3)
:
END SUBROUTINE

END MODULE

The F95 standard, g95 and the Lahey compiler do not allow this mixture
of function and subroutine in the generic interface. On the other hand
gfortran and Intel Fortran compile it and run it successfully.

Who is right? Has the standard changed since F95?

Thank you in advance,

/Sakis


Richard Maine

unread,
Nov 14, 2010, 8:08:24 PM11/14/10
to
Athanasios Migdalas <sa...@otenet.gr> wrote:

> The F95 standard, g95 and the Lahey compiler do not allow this mixture
> of function and subroutine in the generic interface. On the other hand
> gfortran and Intel Fortran compile it and run it successfully.
>
> Who is right? Has the standard changed since F95?

F2003, 16.2.3

"Within a scoping unit, two procedures that have the same generic name
shall both be subroutines or both be functions..."

Pretty straightforward as standard-speak goes. I don't recall these
words as changing much between f90 and f2003.

Note that it is not a constraint, so compilers are not required to
diagnose the error. That means that all of the compilers are "right" in
some sense; allowing this would be an extension rather than an error in
teh compiler.

That being said, at least a warning would be nice, even if not required
by the standard. Have you tried turning on warnings for nonstandard
features in gfortran and Intel?

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

Athanasios Migdalas

unread,
Nov 21, 2010, 6:05:52 PM11/21/10
to
Richard Maine wrote:

> Athanasios Migdalas <sa...@otenet.gr> wrote:
>
>> The F95 standard, g95 and the Lahey compiler do not allow this
mixture
>> of function and subroutine in the generic interface. On the other
hand
>> gfortran and Intel Fortran compile it and run it successfully.
>>
>> Who is right? Has the standard changed since F95?
>
> F2003, 16.2.3
>
> "Within a scoping unit, two procedures that have the same generic
name
> shall both be subroutines or both be functions..."
>
> Pretty straightforward as standard-speak goes. I don't recall these
> words as changing much between f90 and f2003.
>
> Note that it is not a constraint, so compilers are not required to
> diagnose the error. That means that all of the compilers are "right"
in
> some sense; allowing this would be an extension rather than an error
in
> teh compiler.
>
> That being said, at least a warning would be nice, even if not
required
> by the standard. Have you tried turning on warnings for nonstandard
> features in gfortran and Intel?
>

Thank you Richard. You're right, I should have switched on the
compiler warnings.

/Sakis


0 new messages