Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Allocatable vs pointer in procedure resolution
Dear all,

I've come across a situation where I want two versions of a given
subroutine, one which works on pointer-style arrays, and the other which
works on allocatable arrays (via TR 15581).

I've tried putting these routines under the same generic interface, but
the Lahey compiler barfs on this, complaining that the signatures of the
two routines are too similar to disambiguate.

The problem, in essence, is whether it is possible to distinguish
between the signatures of, for instance,

real, dimension(:), pointer :: foo

and

real, dimension(:), allocatable :: foo

I would appreciate hearing:

1) What the F95 (+ TR15581) standard has to say about this -- do these
two dummy arguments have different signatures or not?

2) If not, can anyone envisage a reason why these two dummy arguments
*cannot* be considered to have different signatures?

3) What does the F03 standard have to say about this issue?

cheers,

Rich

--
Dr Richard H D Townsend
Bartol Research Institute
University of Delaware

[ Delete VOID for valid email address ]

Report this thread to moderator Post Follow-up to this message
Old Post
Rich Townsend
07-29-04 08:57 PM


Re: Allocatable vs pointer in procedure resolution
On Thu, 29 Jul 2004 09:59:51 -0400
Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:

> Dear all,
>
> I've come across a situation where I want two versions of a given
> subroutine, one which works on pointer-style arrays, and the other
> which works on allocatable arrays (via TR 15581).
>
> I've tried putting these routines under the same generic interface,
> but the Lahey compiler barfs on this, complaining that the signatures
> of the two routines are too similar to disambiguate.
>
> The problem, in essence, is whether it is possible to distinguish
> between the signatures of, for instance,
>
> real, dimension(:), pointer :: foo
>
> and
>
> real, dimension(:), allocatable :: foo
>
> I would appreciate hearing:
>
> 1) What the F95 (+ TR15581) standard has to say about this -- do these
>
> two dummy arguments have different signatures or not?

I don't have the standard to hand but the Bible (M+R) says that the
arguments must be distinguishable by "type or kind type parameter or ...
rank". So the pointer and/or allocatable attribute appears to be insufficien
t.

>
> 2) If not, can anyone envisage a reason why these two dummy arguments
> *cannot* be considered to have different signatures?
>

No idea. Sorry.

> 3) What does the F03 standard have to say about this issue?
>

Ditto.

> cheers,
>
> Rich
>
> --
> Dr Richard H D Townsend
> Bartol Research Institute
> University of Delaware
>
> [ Delete VOID for valid email address ]

Report this thread to moderator Post Follow-up to this message
Old Post
David Ham
07-29-04 08:57 PM


Re: Allocatable vs pointer in procedure resolution
On Thu, 29 Jul 2004 17:05:28 +0200
David Ham <d.a.ham@citg.tudelft.nl> wrote:

> On Thu, 29 Jul 2004 09:59:51 -0400
> Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote:
> 
>
> I don't have the standard to hand but the Bible (M+R) says that the
> arguments must be distinguishable by "type or kind type parameter or
> ... rank". So the pointer and/or allocatable attribute appears to be
> insufficient.
> 
>
> No idea. Sorry.

Oh, hang on. I think the issue might be that you can't distinguish
either of the above from

real, dimension(:) :: foo

because you can always* pass a pointer or an allocatable array to a
procedure which expects a "plain" array. Maybe the committee decided it
was too confusing/complicated to add the special case of the third side
of the triangle, as it were.

David

*subject to compatibility of other attributes, obviously.

> 
>
> Ditto.
> 

Report this thread to moderator Post Follow-up to this message
Old Post
David Ham
07-29-04 08:57 PM


Re: Allocatable vs pointer in procedure resolution

Rich Townsend wrote:

> Dear all,
>
> I've come across a situation where I want two versions of a given
> subroutine, one which works on pointer-style arrays, and the other which
> works on allocatable arrays (via TR 15581).
>
> I've tried putting these routines under the same generic interface, but
> the Lahey compiler barfs on this, complaining that the signatures of the
> two routines are too similar to disambiguate.
>
> The problem, in essence, is whether it is possible to distinguish
> between the signatures of, for instance,
>
> real, dimension(:), pointer :: foo
>
> and
>
> real, dimension(:), allocatable :: foo
>
> I would appreciate hearing:
>
> 1) What the F95 (+ TR15581) standard has to say about this -- do these
> two dummy arguments have different signatures or not?
No, I don't believe they meet the requirements for being
resolvable.  The standard requires a difference in type (or
kind) or rank as the disambiguators.

>
> 2) If not, can anyone envisage a reason why these two dummy arguments
> *cannot* be considered to have different signatures?
No, I don't think anyone can ;).  Basically, there are many
things that, at least in some cases, could disambiguate some
generics.  Rather than try to come up with a longer list,
I think J3 decided to go with the "obvious" ones and not
try to get all of the special cases.  It would be difficult,
not impossible, to get the words right that would allow you
to overload SQRT to accept character normal arrays,
character allocatables, and character pointers without
messing up the normal SQRT when it has a pointer array as
its argument, etc.  My guess is that it was simply a
judgment call on cost versus benefit.

>
> 3) What does the F03 standard have to say about this issue?

Nothing has changed as far as I can see.

Dick Hendrickson

>
> cheers,
>
> Rich
>


Report this thread to moderator Post Follow-up to this message
Old Post
Dick Hendrickson
07-29-04 08:58 PM


Re: Allocatable vs pointer in procedure resolution
Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote in message news:<ceavs9$r5h$1@scrotar.nss.ud
el.edu>...
> Dear all,
>
> I've come across a situation where I want two versions of a given
> subroutine, one which works on pointer-style arrays, and the other which
> works on allocatable arrays (via TR 15581).
>
> I've tried putting these routines under the same generic interface, but
> the Lahey compiler barfs on this, complaining that the signatures of the
> two routines are too similar to disambiguate.
>
> The problem, in essence, is whether it is possible to distinguish
> between the signatures of, for instance,
>
> real, dimension(:), pointer :: foo
>
> and
>
> real, dimension(:), allocatable :: foo
>
> I would appreciate hearing:
>
> 1) What the F95 (+ TR15581) standard has to say about this -- do these
> two dummy arguments have different signatures or not?

The short and quick answer is: They have not.
Apart from order and number of arguments,
distinction is resolved by TKR: type, kind and rank of arguments.

> 2) If not, can anyone envisage a reason why these two dummy arguments
> *cannot* be considered to have different signatures?

I have no idea why this restriction was made in the standardization process.

> 3) What does the F03 standard have to say about this issue?

AFAIK there is no significant change on this subject in Fortran 2003 .

[JvO]

Report this thread to moderator Post Follow-up to this message
Old Post
jan van oosterwijk
07-29-04 08:58 PM


Re: Allocatable vs pointer in procedure resolution
Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote in message news:<ceavs9$r5h$1
@scrotar.nss.udel.edu>...

> The problem, in essence, is whether it is possible to distinguish
> between the signatures of, for instance,
>
> real, dimension(:), pointer :: foo
>
> and
>
> real, dimension(:), allocatable :: foo
>

Why do you need different procedures? You can do [almost] the same things
with both allocatable arrays and pointers.

Report this thread to moderator Post Follow-up to this message
Old Post
r08n
07-30-04 01:56 PM


Re: Allocatable vs pointer in procedure resolution
r08n wrote:
> Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote in message news:<ceavs9$r5h
$1@scrotar.nss.udel.edu>...
>
> 
>
>
> Why do you need different procedures? You can do [almost] the same things
> with both allocatable arrays and pointers.

I'm writing library routines, and I want the user to be able to
reallocate both POINTER and ALLOCATABLE arrays. Therefore, I have to
provide routines to handle both. I'd like to access these routines under
the same name, but from the replies I've had to my post (thanks to all
who responded!) it looks like this won't be possible.

cheers,

Rich

--
Dr Richard H D Townsend
Bartol Research Institute
University of Delaware

[ Delete VOID for valid email address ]

Report this thread to moderator Post Follow-up to this message
Old Post
Rich Townsend
07-30-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.