function interface question
From: Helge Avlesen (avle_at_tindved.ii.uib.no)
Date: 02/23/05
- Next message: Jan Vorbrüggen: "Re: function interface question"
- Previous message: Michael Metcalf: "Re: Question about modules and namelists"
- Next in thread: Jan Vorbrüggen: "Re: function interface question"
- Reply: Jan Vorbrüggen: "Re: function interface question"
- Reply: Michael Metcalf: "Re: function interface question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Feb 2005 13:29:56 +0100
Hi,
I have an array of a derived type object, where the object contains
pointers to different kinds of basic data types, e.g. arrays of
various dimensions. I would like to have a convenient interface to
fish pointers out of this list, so I tried to make a generic function,
but meet problems...
is it possible, in a "standard" way, to create a generic function from
functions with identical argument list, but different return type?
all compilers I have access to reject the below snippet because they
fail to see the difference between the functions (I guess). on the
other hand compilers seem happy if I return the pointer through the
argument list of a subroutine instead, but I do not really see why
this is easier to swallow for the compiler compared to checking the
return type of the function as below?
--
Helge
module arraylist
type array_element
real, pointer, dimension(:) :: ptr1d
real, pointer, dimension(:,:) :: ptr2d
end type array_element
type hlist
integer last
type(array_element), pointer :: item(:) => null()
end type hlist
interface list_get
module procedure get_item1d, get_item2d
end interface
contains
function get_item1d(list,wanted_n)
implicit none
real, pointer, dimension(:) :: get_item1d
type(hlist) :: list
integer, optional :: wanted_n
integer n
n=list%last
if(present(wanted_n))n=wanted_n
get_item1d => list%item(n)%ptr1d
end function get_item1d
function get_item2d(list,wanted_n)
implicit none
real, pointer, dimension(:,:) :: get_item2d
type(hlist) :: list
integer, optional :: wanted_n
integer n
n=list%last
if(present(wanted_n))n=wanted_n
get_item2d => list%item(n)%ptr2d
end function get_item2d
end module arraylist
- Next message: Jan Vorbrüggen: "Re: function interface question"
- Previous message: Michael Metcalf: "Re: Question about modules and namelists"
- Next in thread: Jan Vorbrüggen: "Re: function interface question"
- Reply: Jan Vorbrüggen: "Re: function interface question"
- Reply: Michael Metcalf: "Re: function interface question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|