Re: generic interface question
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 28 Aug 2007 18:17:41 -0700
fj <francois.jacq@xxxxxxx> wrote:
Yes I have now a small test case which reproduces the trouble :
MODULE a
USE iso_c_binding
INTERFACE
SUBROUTINE foo1(a) BIND(C,name="a_c_routine")
IMPORT C_INT
INTEGER(C_INT) ::a
END SUBROUTINE
END INTERFACE
END MODULE
MODULE b
USE a,ONLY : foo1
INTERFACE foo
MODULE procedure foo1,foo2,foo3
END INTERFACE
CONTAINS
SUBROUTINE foo2(a)
DOUBLE PRECISION ::a
END SUBROUTINE
SUBROUTINE foo3(a)
CHARACTER ::a
END SUBROUTINE
END MODULE
[lcoul@b04p0004 test]$ g95 -c test2.f90
In file test2.f90:13
MODULE procedure foo1,foo2,foo3
1
Error: Cannot change attributes of USE-associated symbol 'foo1' at (1)
Ah. Now that I think I can help with.
The error message is a little confusing (though not so much so as the
paraphrasing that talked about changing host association), but I think
the critical bit here is that foo1 is *NOT* a module procedure.
Yes, I know that you accessed it via a USE statement, but that doesn't
make it a module procedure. It is an external procedure whose interface
happens to be defined in a module.
So I don't think this is a compiler bug, other than perhaps insomuch as
the error message could be better.
There is a bit of "silliness" in the f95 module procedure statement.
Mostly the whole business about restricting it to module procedures is
what seems silly to me. I don't think that restriction was well thought
out. It isn't as though the restriction achieves anything useful. I
think the writers just overlooked the fact that it could be useful for
procedures other than module ones. There are several things that are
really awkward because of this restriction. (Notably, it is hard to put
a single external procedure in two different generics; I'm not even sure
there is a workaround to that one.)
The silliness was fixed in f2003. I don't recall whether Andy yet
implemented the f2003 form of this statement in g95. In f2003, you just
omit the keyword "module" and it no longer has the silly restriction.
Otherwise, if you are stuck with the f95 form, you have to use some kind
of workaround. Ones that occur to me are
1. Put the interface body for foo1 in the generic interface block in
module b (and then don't USE foo1 from module a).
2. Or put a generic interface block for foo in module a, with just foo1
as a specific. You can then extend the generic in module b.
Yes, I know these workarounds can be awkward in some cases. The f2003
fix is better.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: generic interface question
- From: fj
- Re: generic interface question
- References:
- generic interface question
- From: fj
- Re: generic interface question
- From: Richard Maine
- Re: generic interface question
- From: fj
- Re: generic interface question
- From: fj
- generic interface question
- Prev by Date: Re: fortran character set
- Next by Date: Re: fortran character set
- Previous by thread: Re: generic interface question
- Next by thread: Re: generic interface question
- Index(es):
Relevant Pages
|