Re: problem with optional argument
From: Andy Vaught (andy_at_firstinter.net)
Date: 05/24/04
- Next message: Richard Edgar: "Re: [f77] Choosing a complete path"
- Previous message: Hyunsung Jung: "[Greeting] Fortran society in Korea"
- In reply to: Christoph Arns: "problem with optional argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 23 May 2004 23:48:30 -0700
On Thu, 20 May 2004, Christoph Arns wrote:
> Hi all,
>
> below is a little program snipped, which so far I always could use
> successfully in a similar form. Now I got
>
> Error: intfc_test.f90, line 36: Ambiguous specific names PF_INIT_3D and
> PF_INIT_2D in generic PF_INIT
> Errors in declarations, no further processing for INTFC
> Error: intfc_test.f90, line 39: USE of module INTFC which has errors
> Errors in declarations, no further processing for INTFC_TEST
> [f95 error termination]
>
> on an Opteron/NAG/Fedora platform:
>
> NAGWare Fortran 95 Release 5.0
> Linux rsphylc 2.6.5 #1 SMP Fri Apr 16 15:57:37 EST 2004 x86_64 x86_64
> x86_64 GNU/Linux
[...]
> my question: is this a bug, or am I not understanding optional arguments
> in combination with generic interfaces correctly?
G95 craps out on this too but the NAG compiler is good company to be
wrong with. From what I can tell, the bug is in the standard.
When building a list of interfaces, the compiler has to make sure
that they aren't ambiguous. That is, that there does not exist an
actual argument list that could match any two formal interfaces.
There are two main rules used to do this. If either is satisfied,
the interfaces are unambiguous. The first rule involves counting the
number of arguments of a particular type. This rule is used to
account for optional arguments which may or may not be present in the
actual argument list.
The second rule deals with nonoptional arguments and has three parts
that must all be satisfied for it to be true. First, there has to be
a pair of arguments that correspond by position and disagree on type,
rank or kind (or doesn't exist). Second, there has to exist a keyword
(formal argument) name that disagrees by type, rank or kind or doesn't
exist. Last, the argument disagreeing by position has to precede or
be the same as the argument that disambiguates by keyword.
In your example, the first argument that disagrees by position is
the fourth. The *only* keyword that differs is the third argument,
'nz' of the 'pf_init_3d' interface. This precedes the positional
difference so the test fails and the interfaces are ruled ambiguous.
As people have pointed out, the interfaces are not ambiguous at all,
so something is wrong with the rules.
The error appears to be in the third clause, where the sense of the
test should be reversed.
The confusion in this rule probably came from the fact that positional
arguments have to precede keyword arguments in an actual argument list.
But the *disambiguating* keyword argument has to precede the
*disambiguating* positional argument.
If an actual argument list has enough positional arguments to get to
the positionally disambiguating argument, all is well. Otherwise,
there have to be keywords prior to this and they have to disambiguate
the interfaces.
I checked the language in f2003, and it appears that although it
differs from f95 a bit, the problem still exists. If no one cares to
poke a hole in this reasoning, I will see about writing a J3 paper
tomorrow night.
I've fixed this problem in g95 and uploaded it to the usual place at
http://www.g95.org.
Thanks,
Andy
(and thanks to Doug Cox for trying this with g95).
- Next message: Richard Edgar: "Re: [f77] Choosing a complete path"
- Previous message: Hyunsung Jung: "[Greeting] Fortran society in Korea"
- In reply to: Christoph Arns: "problem with optional argument"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|