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

Fortran 2003 questions

6 views
Skip to first unread message

jayd...@googlemail.com

unread,
May 25, 2008, 4:49:22 AM5/25/08
to
Hi,

I have some trouble in interpreting the Fortran 2003 standard.

First question: In section 12.3.2.1 one can read the following:

"An interface body in a generic or specific interface block specifies
the EXTERNAL attribute and an explicit specific interface for an
external procedure or a dummy procedure."

Does this mean that all routines in a (generic or specific) interface
block will get the EXTERNAL attribute? Then the following code should
be invalid, since EXTERNAL is specified twice:

interface
subroutine foo
end subroutine
end interface
external foo

Am I right here, or did I misread something?


Second question: Is the following code valid?

procedure(),pointer :: x
procedure(x) :: y

I assume it is not, because in 12.3.2.3 I find:

"(R1215) The name shall be the name of an abstract interface or of a
procedure that has an
explicit interface. If name is declared by a procedure-declaration-
stmt it shall be previously
declared."

So I guess the problem is be that x does not have an explicit
interface. But would it be valid if x had an explicit interface?

abstract interface
subroutine a
end subroutine
end interface
procedure(a),pointer :: x
procedure(x) :: y

In other words: Can a procedure get its interface from a procedure
pointer? R1215 only mentions abstract interfaces and procedures.

Cheers,
Janus

Tobias Burnus

unread,
May 25, 2008, 5:03:13 AM5/25/08
to
On May 25, 10:49 am, "jaydu...@gmail.com" <jaydu...@googlemail.com>
wrote:

> "An interface body in a generic or specific interface block specifies
> the EXTERNAL attribute and an explicit specific interface for an
> external procedure or a dummy procedure."

Regarding EXTERNAL I have an additional question: Is the following
valid or not?

EXTERNAL func
REAL, DIMENSION(2) :: func

I believe it is valid as neither Janus nor I could find a restriction
in the Fortran 95 or 2003 standard, even though all compilers I tried
reject it.

The following related is however definitely invalid

EXTERNAL func
REAL :: func(2)

as F95 and F2003 [5.1 Type declaration statements] contains:

R504 entity-decl is object-name [( array-spec )] [ * char-length ]
[ initialization ]
or function-name [ * char-length ]

Are we reading the standard correctly? Or is there a clause we have
missed?

Tobias

James Van Buskirk

unread,
May 25, 2008, 11:51:01 AM5/25/08
to
"Tobias Burnus" <bur...@net-b.de> wrote in message
news:d09eca25-3555-41d9...@34g2000hsh.googlegroups.com...

On May 25, 10:49 am, "jaydu...@gmail.com" <jaydu...@googlemail.com>
wrote:
> > "An interface body in a generic or speci?c interface block speci?es
> > the EXTERNAL attribute and an explicit speci?c interface for an

> > external procedure or a dummy procedure."

> Regarding EXTERNAL I have an additional question: Is the following
> valid or not?

> EXTERNAL func
> REAL, DIMENSION(2) :: func

> I believe it is valid as neither Janus nor I could find a restriction
> in the Fortran 95 or 2003 standard, even though all compilers I tried
> reject it.

> The following related is however definitely invalid

> EXTERNAL func
> REAL :: func(2)

> as F95 and F2003 [5.1 Type declaration statements] contains:

> R504 entity-decl is object-name [( array-spec )] [ * char-length ]
> [ initialization ]
> or function-name [ * char-length ]

> Are we reading the standard correctly? Or is there a clause we have
> missed?

Section 12.3.1 of N1601.pdf zaps these examples. You can get an
explicit interface if the procedure is an internal procedure, module
procedure, or intrinsic procedure. Procedures which may call
themselves have an explicit interface to themselves. Otherwise you
need an interface body to get an explicit interface. Then section
12.3.1.1 (3)(a) tells us that you need an explicit interface for an
array-valued function.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Richard Maine

unread,
May 25, 2008, 12:11:53 PM5/25/08
to
jayd...@gmail.com <jayd...@googlemail.com> wrote:

> "An interface body in a generic or specific interface block specifies
> the EXTERNAL attribute and an explicit specific interface for an
> external procedure or a dummy procedure."
>
> Does this mean that all routines in a (generic or specific) interface
> block will get the EXTERNAL attribute? Then the following code should
> be invalid, since EXTERNAL is specified twice:
>
> interface
> subroutine foo
> end subroutine
> end interface
> external foo
>
> Am I right here, or did I misread something?

I'd say you are correct.

>
> Second question: Is the following code valid?
>
> procedure(),pointer :: x
> procedure(x) :: y

No, because, as you say, x needs an explicit interface.

> So I guess the problem is be that x does not have an explicit
> interface. But would it be valid if x had an explicit interface?

Huh? I don't understand the question. The first of those statements
explicitly says that x doesn't have an explicit interface. No, it isn't
valid to say that x doesn't have an explicit interface if there is some
other declaration saying that it does. Is that what you were asking? I'm
not at all sure I'm interpreting the question right.

> abstract interface
> subroutine a
> end subroutine
> end interface
> procedure(a),pointer :: x
> procedure(x) :: y
>
> In other words: Can a procedure get its interface from a procedure
> pointer? R1215 only mentions abstract interfaces and procedures.

Hmm. I think so, but I'm not so sure on that one. Seems like it ought to
be ok, but that doesn't necessarily mean it is. It probably hinges on
whether a procedure pointer counts as a procedure. I think it does, but
that's subtle enough that I'd need quite a bit more coffee first before
reading up on it (and I don't have time for that right now).

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

Richard Maine

unread,
May 25, 2008, 12:11:54 PM5/25/08
to
Tobias Burnus <bur...@net-b.de> wrote:

> Regarding EXTERNAL I have an additional question: Is the following
> valid or not?
>
> EXTERNAL func
> REAL, DIMENSION(2) :: func
>
> I believe it is valid as neither Janus nor I could find a restriction
> in the Fortran 95 or 2003 standard, even though all compilers I tried
> reject it.

No it isn't valid. James gave the reason, but I found part of his
reasoning slightly hard to follow, so I'll repeat it in my words.

Func needs an explicit interface because it is array-valued. The
external statement declares it to have an implicit interface.

> Are we reading the standard correctly? Or is there a clause we have
> missed?

You atre reading it correctly - just not looking in the right places.
You are looking at the syntax. The restriction in question isn't
basically a syntactic one.

Tobias Burnus

unread,
May 25, 2008, 5:06:04 PM5/25/08
to
On May 25, 6:11 pm, nos...@see.signature (Richard Maine) wrote:
> > abstract interface
> >   subroutine a
> >   end subroutine
> > end interface
> > procedure(a),pointer :: x
> > procedure(x) :: y
>
> > In other words: Can a procedure get its interface from a procedure
> > pointer? R1215 only mentions abstract interfaces and procedures.
>
> Hmm. I think so, but I'm not so sure on that one. Seems like it ought to
> be ok, but that doesn't necessarily mean it is. It probably hinges on
> whether a procedure pointer counts as a procedure. I think it does, but
> that's subtle enough that I'd need quite a bit more coffee first before
> reading up on it (and I don't have time for that right now).

"A procedure pointer is a procedure entity that has the POINTER
attribute." (2.4.6 Pointer)

"(R1215) The name shall be the name of an abstract interface or of a
procedure that has an
explicit interface."

Thus is should be OK, I assume.

Regarding my question:


> You atre reading it correctly - just not looking in the right places.
> You are looking at the syntax. The restriction in question isn't
> basically a syntactic one.

Well, with reading correctly I meant also to read the relevant parts;
sometimes I know that it must be somewhere, but still I cannot find it
- and sometimes it helps to read the corrigenda ;-)
(But in general I find the standard quite comprehensible.)

Thanks Richard and James.

Tobias,
who is longing for "The Fortran 2003 Handbook".
("Due: September 2008" in Europe/Africa/Asia/Australia/Oceania and
"already" in August in America.)

0 new messages