Code Comments
Programming Forum and web based access to our favorite programming groups.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 ]
Post Follow-up to this messageOn 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 ]
Post Follow-up to this messageOn 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. >
Post Follow-up to this messageRich 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 >
Post Follow-up to this messageRich 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]
Post Follow-up to this messageRich 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.
Post Follow-up to this messager08n 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 ]
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.