Re: Syntax for passing an external function into a contained function?
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Thu, 22 Dec 2005 13:03:33 -0800
James Giles <jamesgiles@xxxxxxxxxxxxxxxx> wrote:
> ferrad wrote:
> > Still get the unresolved external. (Apologes for the real*8...) I
> > have now:
> > subroutine sub1(func)
> > real*8, external :: func ! put the declaration here !!!
> > x = func1(n)
> > ...
> > contains
> > real*8 function func1(n)
> > func1 = func(n)
> > return
> > end
>
> See above. The internal procedure gets the declaration
> of FUNC by host association and should not declare
> FUNC itself.
To slightly elaborate, when you put the declaration for func inside of
the internal procedure, that *OVERRIDES* the host-associated one from
the dummy argument. It says that in that internal procedure, func does
not refer to the dummy argument, but instead to an external of that name
(which, of course, doesn't exist).
This is a general property of host association - not one specific to
procedures, dummy arguments, or anything else going on here. If you
declare something in the inner scope, that overrides any host associated
thing of the same name. This is a fairly common source of confusions,
and the wisdom of the language design in this area is often debated.
I'll try to avoid restarting such a debate now (I hope). I'm just
describing the way it is - with no judgement about it being good, bad,
or some combination.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.
- Follow-Ups:
- References:
- Syntax for passing an external function into a contained function?
- From: ferrad
- Re: Syntax for passing an external function into a contained function?
- From: James Giles
- Re: Syntax for passing an external function into a contained function?
- From: ferrad
- Re: Syntax for passing an external function into a contained function?
- From: James Giles
- Syntax for passing an external function into a contained function?
- Prev by Date: Re: Syntax for passing an external function into a contained function?
- Next by Date: Scons to build F90, with mixed C. C++
- Previous by thread: Re: Syntax for passing an external function into a contained function?
- Next by thread: Re: Syntax for passing an external function into a contained function?
- Index(es):
Relevant Pages
|